Comments (17)
Naming is, of course, one of the hard problems in software... what would you call this strategy?
from decorators.
I rather like 'Renovators'.
from decorators.
Wouldn't it still load app/decorators/*_/__decorator.rb though?
from decorators.
Why not change it to app/renovators/**/*_renovator.rb
? That seems like a more apt name and place. The decorator already exists in a couple different formats in Rails (it's also a shitty name for a pattern that's more like a view controller).
I do get why 'decorator' was used for that pattern, and what people do with Refinery-style decorators is the decorator pattern, but since it's applied to the object's class instance, it's stretching the definition.
Really, this is monkeypatching, but that has such negative connotations, and just 'patching' is already taken, too. What Refinery-style decorators do is renovate a class—take an existing behaviour, and tack on some cool crap. Renovation.
from decorators.
I could not find a software pattern name for monkey patching.
How about "Extensions", and app/extensions/**/*_extension.rb
?
Or, perhaps "Extenders".
from decorators.
When I think of the "decorator pattern", such as described here, the decorator wraps an object to give the object extra behaviour; without modifying other objects of the same class.
Example:
class Person
def save
# saves record
end
end
class NotificationDecorator
def initialize person
@person = person
end
def save
# send notification
@person.save
end
end
NotificationDecorator.new(Person.new).save
Here NotificationDecorator
would have the same public interface as Person
, just adding behaviour where needed.
Using the Queen's english for Philip's sake.
from decorators.
So the decorator pattern is not 100% what we're doing because that involves decorating individual instances of the class. We're decorating the class.
A perfect name, keeping decorators, would be class_decorators or something along those lines.
Extenders seems legitimate too.. but there's a lot of applications already using app/decorators/ as a convention so it would be a hard sell.
If it were to change the convention now there'd have to be some sort of compatibility adapter for using decorators/ too with a nice little warning saying please update to extenders.
What do you all think?
from decorators.
Yep, and instance decorators are already a solved problem by Draper.
from decorators.
Don't get me wrong, I'm not saying what this is intended for is not useful.
Draper does provide a pattern for decorators, but specifically intended to be used in views -- "View Decorators" if you will. But, the pattern itself is not limited to that.
from decorators.
You're trying to solve a problem related to Refinery, but Refinery isn't mentioned anywhere. That alone might do it, IMHO.
from decorators.
Related to Refinery, Spree, Forem, etc.
from decorators.
Since this is just simple monkey patching, we should call it Banana
. Files will be stored in app/bananas/**/*_banana.rb
path and for profit we should alias Kernel.class_eval
into Kernel.monkey_patch
.
from decorators.
+1 for extenders but I'm also fine with decorators, (why change something that works?) .)
from decorators.
I would prefer renovators/extenders. Actually, probably extenders because its 1chr shorter.
Or bananas. Bananas works too.
from decorators.
But... but... Tim the Toolman.
from decorators.
@radar I made little name length's benchmark for you:
name | name.length
--------------------------
renovators | 10
extenders | 9
bananas | 7
I think we have winner!
from decorators.
@parndt :( ?
from decorators.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decorators.