Module: Draper::DecoratesAssigned
- Defined in:
- lib/draper/decorates_assigned.rb
Instance Method Summary collapse
-
#decorates_assigned(*variables, options = {}) ⇒ Object
Defines a helper method to access decorated instance variables.
Instance Method Details
#decorates_assigned(*variables, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/draper/decorates_assigned.rb', line 28 def decorates_assigned(*variables) factory = Draper::Factory.new(variables.) variables.each do |variable| undecorated = "@#{variable}" decorated = "@decorated_#{variable}" define_method variable do return instance_variable_get(decorated) if instance_variable_defined?(decorated) instance_variable_set decorated, factory.decorate(instance_variable_get(undecorated), context_args: self) end helper_method variable end end |