Class: FactoryBurgers::Models::Factory
- Inherits:
-
Object
- Object
- FactoryBurgers::Models::Factory
- Defined in:
- lib/factory_burgers/models/factory.rb
Overview
Represent a factory and associated data needed for UI TODO: support transient attributes (f.definition.attributes …?) TODO: support associations
Instance Attribute Summary collapse
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
Instance Method Summary collapse
- #attributes ⇒ Object
- #class_name ⇒ Object
-
#initialize(factory) ⇒ Factory
constructor
A new instance of Factory.
- #name ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
- #traits ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(factory) ⇒ Factory
Returns a new instance of Factory.
11 12 13 |
# File 'lib/factory_burgers/models/factory.rb', line 11 def initialize(factory) @factory = factory end |
Instance Attribute Details
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
9 10 11 |
# File 'lib/factory_burgers/models/factory.rb', line 9 def factory @factory end |
Instance Method Details
#attributes ⇒ Object
44 45 46 |
# File 'lib/factory_burgers/models/factory.rb', line 44 def attributes settable_columns.map { |col| Attribute.new(col) } end |
#class_name ⇒ Object
36 37 38 |
# File 'lib/factory_burgers/models/factory.rb', line 36 def class_name build_class.base_class.name end |
#name ⇒ Object
32 33 34 |
# File 'lib/factory_burgers/models/factory.rb', line 32 def name factory.name.to_s end |
#to_h ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/factory_burgers/models/factory.rb', line 19 def to_h { name: name, class_name: class_name, traits: traits.map(&:to_h), attributes: attributes.map(&:to_h), } end |
#to_json ⇒ Object
28 29 30 |
# File 'lib/factory_burgers/models/factory.rb', line 28 def to_json(...) to_h.to_json(...) end |
#traits ⇒ Object
40 41 42 |
# File 'lib/factory_burgers/models/factory.rb', line 40 def traits defined_traits.map { |trait| Trait.new(trait) } end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/factory_burgers/models/factory.rb', line 15 def valid? build_class.present? end |