Class: FactoryBurgers::Presenters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_burgers/presenters/base.rb

Overview

Presenter classes are responsible for formatting application object data for the UI. This defatul presenter will display the id and name attributes, if they exist, and does not have an application link. Create subclasses of this class to present different information for different application models.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Base

Returns a new instance of Base.



16
17
18
# File 'lib/factory_burgers/presenters/base.rb', line 16

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



14
15
16
# File 'lib/factory_burgers/presenters/base.rb', line 14

def object
  @object
end

Class Method Details

.presents(name) ⇒ Object



9
10
11
# File 'lib/factory_burgers/presenters/base.rb', line 9

def presents(name)
  define_method(name) { object }
end

Instance Method Details

#attributesObject



24
25
26
# File 'lib/factory_burgers/presenters/base.rb', line 24

def attributes
  object.attributes.slice("id", "name")
end


28
29
30
# File 'lib/factory_burgers/presenters/base.rb', line 28

def link_path
  nil
end

#typeObject



20
21
22
# File 'lib/factory_burgers/presenters/base.rb', line 20

def type
  object.class.name
end