Class: ROM::Factory::TupleEvaluator Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#attributesObject (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

#modelObject (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

#relationObject (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

#sequenceObject (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_namesObject

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.

Returns:

  • (Boolean)


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_keyObject

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