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
45 46 47 |
# File 'lib/factory_burgers/models/factory.rb', line 45 def attributes settable_columns.map { |col| Attribute.new(col) } end |
#class_name ⇒ Object
37 38 39 |
# File 'lib/factory_burgers/models/factory.rb', line 37 def class_name active_record? ? build_class.base_class.name : build_class.name end |
#name ⇒ Object
33 34 35 |
# File 'lib/factory_burgers/models/factory.rb', line 33 def name factory.name.to_s end |
#to_h ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/factory_burgers/models/factory.rb', line 20 def to_h { name: name, class_name: class_name, traits: traits.map(&:to_h), attributes: attributes.map(&:to_h), } end |
#to_json ⇒ Object
29 30 31 |
# File 'lib/factory_burgers/models/factory.rb', line 29 def to_json(...) to_h.to_json(...) end |
#traits ⇒ Object
41 42 43 |
# File 'lib/factory_burgers/models/factory.rb', line 41 def traits defined_traits.map { |trait| Trait.new(trait) } end |
#valid? ⇒ Boolean
15 16 17 18 |
# File 'lib/factory_burgers/models/factory.rb', line 15 def valid? # Non-ActiveRecord factories are not supported; we don't know how to set their columns, persist records, etc. active_record? end |