module DraftApprove::Draftable::InstanceMethods
Instance methods automatically added to an ActiveRecord model when acts_as_draftable
is called
Public Instance Methods
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.
@param options [Hash] the options to save the draft with @option options [Symbol] :delete_method the method to use to delete
the object when this draft is approved, eg. +:delete+. This must be a method available on the object. The default is +destroy!+.
@return [Draft] the Draft
object which was created
# File lib/draft_approve/draftable/instance_methods.rb, line 59 def draft_destroy!(options = nil) DraftApprove::Persistor.write_draft_from_model(Draft::DELETE, self, options) end
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.
@param options [Hash] the options to save the draft with @option options [Symbol] :validate whether to validate the model before
draft changes are saved, defaults to +true+
@option options [Symbol] :create_method the method to use when creating
a new object from this draft, eg. +:find_or_create_by!+. This must be a method available on the object, and must accept a hash of attribute names to attribute values. The default is +create!+. Ignored if this draft is for an object which has already been persisted.
@option options [Symbol] :update_method the method to use when updating
an existing object from this draft, eg. +:update_columns+. This must be a method available on the object, and must accept a hash of attribute names to attribute values. The default is +update!+. Ignored if this draft is for an object which has not yet been persisted.
@return [Draft, nil] the Draft
object which was created, or nil
if
there were no changes to the object
# File lib/draft_approve/draftable/instance_methods.rb, line 40 def draft_save!(options = nil) if self.new_record? DraftApprove::Persistor.write_draft_from_model(Draft::CREATE, self, options) else DraftApprove::Persistor.write_draft_from_model(Draft::UPDATE, self, options) end end
Updates an existing object with the given attributes, and saves the updates as a draft.
@param attributes [Hash] a hash of attribute names to attribute values,
like the hash expected by the ActiveRecord +update+ / +update!+ methods
@return [Draft, nil] the Draft
object which was created, or nil
if
there were no changes to the object
# File lib/draft_approve/draftable/instance_methods.rb, line 74 def draft_update!(attributes) self.assign_attributes(attributes) self.draft_save! end
Whether this object is draftable. Helper method to identify draftable objects.
@return [Boolean] true
# File lib/draft_approve/draftable/instance_methods.rb, line 15 def draftable? true end