Class: PluckMap::Presenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Instance Attribute Details

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/pluck_map/presenter.rb', line 31

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