Class: MR::Factory::RecordStack
- Inherits:
-
Object
- Object
- MR::Factory::RecordStack
- Defined in:
- lib/mr/factory/record_stack.rb
Defined Under Namespace
Classes: AssociationData, RecordData
Instance Attribute Summary collapse
-
#factory_config ⇒ Object
readonly
Returns the value of attribute factory_config.
-
#record_data ⇒ Object
readonly
Returns the value of attribute record_data.
-
#record_lookup ⇒ Object
readonly
Returns the value of attribute record_lookup.
-
#record_stacks ⇒ Object
readonly
Returns the value of attribute record_stacks.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #create_dependencies ⇒ Object (also: #create_deps)
- #destroy ⇒ Object
- #destroy_dependencies ⇒ Object (also: #destroy_deps)
-
#initialize(record_data, factory_config, record_lookup = nil) ⇒ RecordStack
constructor
A new instance of RecordStack.
- #record ⇒ Object
Constructor Details
#initialize(record_data, factory_config, record_lookup = nil) ⇒ RecordStack
Returns a new instance of RecordStack.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mr/factory/record_stack.rb', line 16 def initialize(record_data, factory_config, record_lookup = nil) @record_data = record_data @factory_config = factory_config @record_lookup = record_lookup || build_lookup(@record_data) @record_stacks = @record_data.association_datas.map do |association_data| next unless association_data.required?(factory_config) associated_record_data = association_data.get_record_data( @factory_config, @record_lookup ) associated_factory_config = @factory_config.factory_config_for( association_data.name, associated_record_data.record_class ) @record_lookup[associated_record_data.record_class] ||= associated_record_data @record_data.set_association(association_data.name, associated_record_data) MR::Factory::RecordStack.new( associated_record_data, associated_factory_config, @record_lookup ) end.compact end |
Instance Attribute Details
#factory_config ⇒ Object (readonly)
Returns the value of attribute factory_config.
13 14 15 |
# File 'lib/mr/factory/record_stack.rb', line 13 def factory_config @factory_config end |
#record_data ⇒ Object (readonly)
Returns the value of attribute record_data.
13 14 15 |
# File 'lib/mr/factory/record_stack.rb', line 13 def record_data @record_data end |
#record_lookup ⇒ Object (readonly)
Returns the value of attribute record_lookup.
13 14 15 |
# File 'lib/mr/factory/record_stack.rb', line 13 def record_lookup @record_lookup end |
#record_stacks ⇒ Object (readonly)
Returns the value of attribute record_stacks.
14 15 16 |
# File 'lib/mr/factory/record_stack.rb', line 14 def record_stacks @record_stacks end |
Class Method Details
.for_record(record, factory_config) ⇒ Object
9 10 11 |
# File 'lib/mr/factory/record_stack.rb', line 9 def self.for_record(record, factory_config) self.new(RecordData.new(record), factory_config) end |
Instance Method Details
#create ⇒ Object
46 47 48 49 50 |
# File 'lib/mr/factory/record_stack.rb', line 46 def create self.create_dependencies self.record_data.create_record true end |
#create_dependencies ⇒ Object Also known as: create_deps
58 59 60 61 62 |
# File 'lib/mr/factory/record_stack.rb', line 58 def create_dependencies self.record_stacks.each(&:create) self.record_data.refresh_record_associations true end |
#destroy ⇒ Object
52 53 54 55 56 |
# File 'lib/mr/factory/record_stack.rb', line 52 def destroy self.record_data.destroy_record self.destroy_dependencies true end |
#destroy_dependencies ⇒ Object Also known as: destroy_deps
65 66 67 68 |
# File 'lib/mr/factory/record_stack.rb', line 65 def destroy_dependencies self.record_stacks.each(&:destroy) true end |
#record ⇒ Object
42 43 44 |
# File 'lib/mr/factory/record_stack.rb', line 42 def record self.record_data.record end |