Module: Disposable::Twin::Save

Defined in:
lib/disposable/twin/save.rb

Instance Method Summary collapse

Instance Method Details

#save(options = {}, &block) ⇒ Object

Returns the result of that save invocation on the model.



4
5
6
7
8
9
# File 'lib/disposable/twin/save.rb', line 4

def save(options={}, &block)
  res = sync(&block)
  return res if block_given?

  save!(options)
end

#save!(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/disposable/twin/save.rb', line 11

def save!(options={})
  result = save_model

  schema.each(twin: true) do |dfn|
    next if dfn[:save] == false

    # call #save! on all nested twins.
    PropertyProcessor.new(dfn, self).() { |twin| twin.save! }
  end

  result
end

#save_modelObject



24
25
26
# File 'lib/disposable/twin/save.rb', line 24

def save_model
  model.save
end