Module: ObjectAttorney::OrmHandlers::SmoothOperator

Defined in:
lib/object_attorney/orm_handlers/smooth_operator.rb

Instance Method Summary collapse

Instance Method Details

#call_save_or_destroy(object, save_method, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/object_attorney/orm_handlers/smooth_operator.rb', line 27

def call_save_or_destroy(object, save_method, options = {})
  if object == self || object == represented_object
    represented_object.present? ? represented_object.send(save_method, options).ok? : true
  else
    save_method = :destroy if Helpers.marked_for_destruction?(object)
    object.send(save_method, options).ok?
  end
end

#destroy(options = {}) ⇒ Object



22
23
24
25
# File 'lib/object_attorney/orm_handlers/smooth_operator.rb', line 22

def destroy(options = {})
  return true if represented_object.blank?
  represented_object.destroy(options).ok?
end

#save(options = {}) ⇒ Object



6
7
8
# File 'lib/object_attorney/orm_handlers/smooth_operator.rb', line 6

def save(options = {})
  save_or_! { submit(options) }
end

#save!(options = {}) ⇒ Object



10
11
12
# File 'lib/object_attorney/orm_handlers/smooth_operator.rb', line 10

def save!(options = {})
  save_or_! { submit!(options) }
end

#submit(options = {}) ⇒ Object



14
15
16
# File 'lib/object_attorney/orm_handlers/smooth_operator.rb', line 14

def submit(options = {})
  submit_or_!(:save, options)
end

#submit!(options = {}) ⇒ Object



18
19
20
# File 'lib/object_attorney/orm_handlers/smooth_operator.rb', line 18

def submit!(options = {})
  submit_or_!(:save!, options)
end