Class: PluckMap::Presenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CsvPresenter

#to_csv

Methods included from HashPresenter

#to_h

Methods included from JsonPresenter

#to_json

Constructor Details

#initialize(model = nil, attributes = nil, &block) ⇒ Presenter



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

def initialize(model = nil, attributes = nil, &block)
  if block_given?
    puts "DEPRECATION WARNING: `PluckMap::Presenter.new` will be deprecated. Use `PluckMap[Model].define` instead."
    @attributes = PluckMap::AttributeBuilder.build(model: nil, &block)
  else
    @model = model
    @attributes = attributes
  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

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#no_map?Boolean



27
28
29
# File 'lib/pluck_map/presenter.rb', line 27

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