Class: PluckMap::Presenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashPresenter

#to_h

Constructor Details

#initialize(&block) ⇒ Presenter

Returns a new instance of Presenter.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pluck_map/presenter.rb', line 10

def initialize(&block)
  @attributes = PluckMap::AttributeBuilder.build(&block)

  @attributes_by_id = {}
  @selects = []
  attributes.each do |attribute|
    attribute.indexes = attribute.selects.map do |select|
      selects.find_index(select) || begin
        selects.push(select)
        selects.length - 1
      end
    end
    attributes_by_id[attribute.id] = attribute
  end

  if respond_to?(:define_presenters!, true)
    puts "DEPRECATION WARNING: `define_presenters!` is deprecated; instead mix in a module that implements your presenter method (e.g. `to_h`). Optionally have the method redefine itself the first time it is called."
    # because overridden `define_presenters!` will probably call `super`
    PluckMap::Presenter.class_eval 'protected def define_presenters!; end'
    define_presenters!
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/pluck_map/presenter.rb', line 8

def attributes
  @attributes
end

Instance Method Details

#no_map?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/pluck_map/presenter.rb', line 33

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