Class: FactoryBurgers::Models::FactoryOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_burgers/models/factory_output.rb

Overview

Data class for the output of a factory create action

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ FactoryOutput

‘object` is whatever the output of `Factory#create` was



8
9
10
11
# File 'lib/factory_burgers/models/factory_output.rb', line 8

def initialize(object)
  @object = object
  @presenter = FactoryBurgers::Presenters.presenter_for(object)
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/factory_burgers/models/factory_output.rb', line 5

def object
  @object
end

#presenterObject (readonly)

Returns the value of attribute presenter.



5
6
7
# File 'lib/factory_burgers/models/factory_output.rb', line 5

def presenter
  @presenter
end

Instance Method Details

#dataObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/factory_burgers/models/factory_output.rb', line 13

def data
  # TODO: Sorting by name is a UI concern; move it there.
  sorted_assocs = association_factories.sort_by { |item| item[:association].name }
  # TODO: group type, attributes, and link into `object`, move keys into presenter
  return {
    type: presenter.type,
    attributes: presenter.attributes,
    link: presenter.link_path,
    association_factories: sorted_assocs.map { |item| association_factory_data(item) },
  }
end