Class: PluckMap::Presenter
- Inherits:
-
Object
- Object
- PluckMap::Presenter
- Defined in:
- lib/pluck_map/presenter.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Presenter
constructor
A new instance of Presenter.
- #method_missing(attribute_name, *args, &block) ⇒ Object
- #no_map? ⇒ Boolean
Constructor Details
#initialize(&block) ⇒ Presenter
Returns a new instance of Presenter.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pluck_map/presenter.rb', line 8 def initialize(&block) @attributes = [] if block.arity == 1 block.call(self) else instance_eval(&block) end @initialized = true @attributes_by_id = attributes.index_by(&:id).with_indifferent_access @keys = attributes.flat_map(&:keys).uniq define_presenters! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attribute_name, *args, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/pluck_map/presenter.rb', line 23 def method_missing(attribute_name, *args, &block) return super if initialized? = args. [:value] = args.first if args.any? attributes.push PluckMap::Attribute.new(attribute_name, ) :attribute_added end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/pluck_map/presenter.rb', line 6 def attributes @attributes end |
Instance Method Details
#no_map? ⇒ Boolean
31 32 33 |
# File 'lib/pluck_map/presenter.rb', line 31 def no_map? attributes.all?(&:no_map?) end |