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.



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

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.



9
10
11
# File 'lib/rom/factory/builder/persistable.rb', line 9

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.



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

def relation
  @relation
end

Instance Method Details

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



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

def create(attrs = {})
  tuple = tuple(attrs)
  persisted = persist(tuple)

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

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

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