Module: ActsAsApprovable::Model
- Defined in:
- lib/acts_as_approvable/model.rb,
lib/acts_as_approvable/model/class_methods.rb,
lib/acts_as_approvable/model/instance_methods.rb,
lib/acts_as_approvable/model/create_instance_methods.rb,
lib/acts_as_approvable/model/update_instance_methods.rb
Overview
The meat of ActsAsApprovable. This applies methods for the configured approval events and configures the required relationships.
Defined Under Namespace
Modules: ClassMethods, CreateInstanceMethods, InstanceMethods, UpdateInstanceMethods
Instance Method Summary collapse
-
#acts_as_approvable(options = {}) ⇒ Object
Declare this in your model to require approval on new records or changes to fields.
Instance Method Details
#acts_as_approvable(options = {}) ⇒ Object
Declare this in your model to require approval on new records or changes to fields.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/acts_as_approvable/model.rb', line 19 def acts_as_approvable( = {}) extend ClassMethods include InstanceMethods cattr_accessor :approvable_on self.approvable_on = Array.wrap(.delete(:on) { [:create, :update] }) cattr_accessor :approvable_field self.approvable_field = .delete(:state_field) cattr_accessor :approvable_ignore ignores = Array.wrap(.delete(:ignore) { [] }) ignores.push('created_at', 'updated_at', primary_key, self.approvable_field) self.approvable_ignore = ignores.compact.uniq.map(&:to_s) cattr_accessor :approvable_only self.approvable_only = Array.wrap(.delete(:only) { [] }).uniq.map(&:to_s) cattr_accessor :approvals_disabled self.approvals_disabled = false has_many :approvals, :as => :item, :dependent => :destroy if approvable_on?(:update) include UpdateInstanceMethods before_update :approvable_update, :if => :approvable_update? end if approvable_on?(:create) include CreateInstanceMethods before_create :approvable_create, :if => :approvable_create? end after_save :approvable_save, :if => :approvals_enabled? end |