Module: DraftApprove::Draftable::InstanceMethods
- Defined in:
- lib/draft_approve/draftable/instance_methods.rb
Overview
Instance methods automatically added to an ActiveRecord model when acts_as_draftable
is called
Instance Method Summary collapse
-
#draft_destroy!(options = nil) ⇒ Draft
Marks this object to be destroyed when this draft change is approved.
-
#draft_save!(options = nil) ⇒ Draft?
Saves any changes to the object as a draft.
-
#draft_update!(attributes) ⇒ Draft?
Updates an existing object with the given attributes, and saves the updates as a draft.
-
#draftable? ⇒ Boolean
Whether this object is draftable.
Instance Method Details
#draft_destroy!(options = nil) ⇒ Draft
Marks this object to be destroyed when this draft change is approved.
This method should only be called on objects which have already been persisted.
59 60 61 |
# File 'lib/draft_approve/draftable/instance_methods.rb', line 59 def draft_destroy!( = nil) DraftApprove::Persistor.write_draft_from_model(Draft::DELETE, self, ) end |
#draft_save!(options = nil) ⇒ Draft?
Saves any changes to the object as a draft.
This method may be called both on a new object which has not been persisted yet, and on objects which have already been persisted.
40 41 42 43 44 45 46 |
# File 'lib/draft_approve/draftable/instance_methods.rb', line 40 def draft_save!( = nil) if self.new_record? DraftApprove::Persistor.write_draft_from_model(Draft::CREATE, self, ) else DraftApprove::Persistor.write_draft_from_model(Draft::UPDATE, self, ) end end |
#draft_update!(attributes) ⇒ Draft?
Updates an existing object with the given attributes, and saves the updates as a draft.
74 75 76 77 |
# File 'lib/draft_approve/draftable/instance_methods.rb', line 74 def draft_update!(attributes) self.assign_attributes(attributes) self.draft_save! end |
#draftable? ⇒ Boolean
Whether this object is draftable. Helper method to identify draftable objects.
15 16 17 |
# File 'lib/draft_approve/draftable/instance_methods.rb', line 15 def draftable? true end |