Class: GenericViewMapper::Attribute
- Inherits:
-
Object
- Object
- GenericViewMapper::Attribute
- Defined in:
- lib/generic_view_mapper/view/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #field_name ⇒ Object
-
#initialize(name, options) ⇒ Attribute
constructor
A new instance of Attribute.
- #render(target, view_context) ⇒ Object
- #send_to(target, view_context) ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 |
# File 'lib/generic_view_mapper/view/attribute.rb', line 7 def initialize(name, ) @name = name = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/generic_view_mapper/view/attribute.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/generic_view_mapper/view/attribute.rb', line 5 def end |
Instance Method Details
#field_name ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/generic_view_mapper/view/attribute.rb', line 12 def field_name .fetch(:as) { name } .to_s .camelize(:lower) .to_sym end |
#render(target, view_context) ⇒ Object
30 31 32 |
# File 'lib/generic_view_mapper/view/attribute.rb', line 30 def render(target, view_context) { field_name => send_to(target, view_context) } end |
#send_to(target, view_context) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/generic_view_mapper/view/attribute.rb', line 20 def send_to(target, view_context) name.to_s.split('.').inject(target) do |obj, method| if view_context.respond_to?(method) view_context.public_send(method) else obj.public_send(method) end end end |