Class: ROM::Factory::Builder::Persistable Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rom/factory/builder/persistable.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(builder, relation = builder.relation) ⇒ Persistable

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 Persistable.



17
18
19
20
21
# File 'lib/rom/factory/builder/persistable.rb', line 17

def initialize(builder, relation = builder.relation)
  super(builder)
  @builder = builder
  @relation = relation
end

Instance Attribute Details

#builderObject (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.



11
12
13
# File 'lib/rom/factory/builder/persistable.rb', line 11

def builder
  @builder
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.



14
15
16
# File 'lib/rom/factory/builder/persistable.rb', line 14

def relation
  @relation
end

Instance Method Details

#create(*traits, **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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rom/factory/builder/persistable.rb', line 24

def create(*traits, **attrs)
  validate_keys(traits, attrs)

  tuple = tuple(*traits, **attrs)
  persisted = persist(tuple)

  if tuple_evaluator.has_associations?(traits)
    tuple_evaluator.persist_associations(tuple, persisted, traits)

    pk = primary_key_names.map { |key| persisted[key] }

    relation.by_pk(*pk).combine(*tuple_evaluator.assoc_names(traits)).first
  else
    persisted
  end
end