Class: PluckMap::Presenter
- Inherits:
-
Object
- Object
- PluckMap::Presenter
- Defined in:
- lib/pluck_map/presenter.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pluck_map/presenter.rb', line 14 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
29 30 31 32 33 34 35 |
# File 'lib/pluck_map/presenter.rb', line 29 def method_missing(attribute_name, *args, &block) return super if initialized? = args. [:value] = args.first unless args.empty? attributes.push PluckMap::Attribute.new(attribute_name, ) :attribute_added end |
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/pluck_map/presenter.rb', line 11 def logger @logger end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/pluck_map/presenter.rb', line 7 def attributes @attributes end |
Instance Method Details
#no_map? ⇒ Boolean
37 38 39 |
# File 'lib/pluck_map/presenter.rb', line 37 def no_map? attributes.all?(&:no_map?) end |