Module: ObjectAttorney::Record
- Defined in:
- lib/object_attorney/record.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #call_save_or_destroy(object, save_method) ⇒ Object
- #clear_nested_imposed_errors ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #populate_nested_imposed_errors ⇒ Object
- #save ⇒ Object
- #save!(save_method = :save!) ⇒ Object
- #submit ⇒ Object
- #submit! ⇒ Object
Instance Method Details
#call_save_or_destroy(object, save_method) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/object_attorney/record.rb', line 38 def call_save_or_destroy(object, save_method) if object == self represented_object.present? ? represented_object.send(save_method) : true else save_method = :destroy if Helpers.marked_for_destruction?(object) object.send(save_method) end end |
#clear_nested_imposed_errors ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/object_attorney/record.rb', line 47 def clear_nested_imposed_errors nested_objects.each do |reflection, nested_object| nested_object.clear_imposed_errors nested_object.clear_nested_imposed_errors if nested_object.respond_to?(:clear_nested_imposed_errors) end end |
#destroy ⇒ Object
33 34 35 36 |
# File 'lib/object_attorney/record.rb', line 33 def destroy return true if represented_object.blank? represented_object.destroy end |
#id ⇒ Object
5 6 7 |
# File 'lib/object_attorney/record.rb', line 5 def id represented_object.try(:id) end |
#new_record? ⇒ Boolean
9 10 11 |
# File 'lib/object_attorney/record.rb', line 9 def new_record? Helpers.try_or_return(represented_object, :new_record?, true) end |
#persisted? ⇒ Boolean
13 14 15 |
# File 'lib/object_attorney/record.rb', line 13 def persisted? Helpers.try_or_return(represented_object, :persisted?, false) end |
#populate_nested_imposed_errors ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/object_attorney/record.rb', line 55 def populate_nested_imposed_errors nested_objects.each do |reflection, nested_object| next if Helpers.marked_for_destruction?(nested_object) nested_object.populate_imposed_errors nested_object.populate_nested_imposed_errors if nested_object.respond_to?(:populate_nested_imposed_errors) end end |
#save ⇒ Object
17 18 19 |
# File 'lib/object_attorney/record.rb', line 17 def save save_or_! { submit } end |
#save!(save_method = :save!) ⇒ Object
21 22 23 |
# File 'lib/object_attorney/record.rb', line 21 def save!(save_method = :save!) save_or_! { submit! } end |
#submit ⇒ Object
25 26 27 |
# File 'lib/object_attorney/record.rb', line 25 def submit submit_or_!(:save) end |
#submit! ⇒ Object
29 30 31 |
# File 'lib/object_attorney/record.rb', line 29 def submit! submit_or_!(:save!) end |