Given that I have a class that inherits from Draper::Decorator, like this:
class PageDecorator < Draper::Decorator
delegate_all
delegate :title, :name, :region, :keys,
to: :glass_decorator,
prefix: :glass
def full_title
full_title = []
full_title << glass_title if glass_title
full_title.join(" ")
end
There is a decorator called GlassDecorator in another file in the same directory.
What does the
delegateline actually mean? Does it mean that when I try to access thetitle,name,region,keysattributes/methods, they will be delegated to theGlassDecorator? What does theprefix:part mean?For the
full_titlemethod, Does theglass_titlepart try to lookup thetitleattribute/method in theGlassDecorator? If that is the case, is it made possible only because of thedelegateline? If so, is it the:prefixportion that makes it possible?
Thank you.
1)
:prefixwill add the prefix to the front of the method-name. eg "glass_title" instead of just "title"delegatemeans that if somebody callsglass_titleon yourPageDecorator, it will then go and calltitleon theGlassDecoratorand hand you the result. ie - it delegates that method to the object named in:to2) yes. You have understood that correctly