Class: PluckMap::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/pluck_map/presenter.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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?
  options = args.extract_options!
  options[:value] = args.first unless args.empty?
  attributes.push PluckMap::Attribute.new(attribute_name, options)
  :attribute_added
end

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/pluck_map/presenter.rb', line 11

def logger
  @logger
end

Instance Attribute Details

#attributesObject (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

Returns:

  • (Boolean)


37
38
39
# File 'lib/pluck_map/presenter.rb', line 37

def no_map?
  attributes.all?(&:no_map?)
end