Class: ROM::Factory::TupleEvaluator Private
- Inherits:
-
Object
- Object
- ROM::Factory::TupleEvaluator
- Defined in:
- lib/rom/factory/tuple_evaluator.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #attributes ⇒ Object readonly private
- #model ⇒ Object readonly private
- #relation ⇒ Object readonly private
- #sequence ⇒ Object readonly private
Instance Method Summary collapse
- #assoc_names ⇒ Object private
- #defaults(attrs) ⇒ Object private
- #has_associations? ⇒ Boolean private
-
#initialize(attributes, relation) ⇒ TupleEvaluator
constructor
private
A new instance of TupleEvaluator.
- #persist_associations(tuple, parent) ⇒ Object private
- #primary_key ⇒ Object private
- #struct(attrs) ⇒ Object private
Constructor Details
#initialize(attributes, relation) ⇒ TupleEvaluator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TupleEvaluator.
18 19 20 21 22 23 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 18 def initialize(attributes, relation) @attributes = attributes @relation = relation.with(auto_struct: true) @model = @relation.combine(*assoc_names).mapper.model @sequence = 0 end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 6 def attributes @attributes end |
#model ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 12 def model @model end |
#relation ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 9 def relation @relation end |
#sequence ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 15 def sequence @sequence end |
Instance Method Details
#assoc_names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 44 def assoc_names attributes.associations.map(&:name) end |
#defaults(attrs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 26 def defaults(attrs) evaluate(attrs).merge(attrs) end |
#has_associations? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 49 def has_associations? assoc_names.size > 0 end |
#persist_associations(tuple, parent) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 36 def persist_associations(tuple, parent) assoc_names.each do |name| assoc = tuple[name] assoc.(parent) if assoc.is_a?(Proc) end end |
#primary_key ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 54 def primary_key relation.primary_key end |
#struct(attrs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/rom/factory/tuple_evaluator.rb', line 31 def struct(attrs) model.new(struct_attrs.merge(defaults(attrs))) end |