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

Returns a new instance of Presenter.



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

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.



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

def attributes
  @attributes
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#no_map?Boolean

Returns:

  • (Boolean)


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

def no_map?
  puts "DEPRECATION WARNING: `PluckMap::Presenter#no_map?` is deprecated. You can replace it with `!attributes.will_map?`"
  !attributes.will_map?
end