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,
lib/acts_as_approvable/model/destroy_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, DestroyInstanceMethods, 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.
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 54 55 56 57 58 |
# File 'lib/acts_as_approvable/model.rb', line 20 def acts_as_approvable( = {}) extend ClassMethods include InstanceMethods cattr_accessor :approvable_on self.approvable_on = Array.wrap(.delete(:on) { [:create, :update, :destroy] }) 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 if approvable_on?(:destroy) include DestroyInstanceMethods end after_save :approvable_save, :if => :approvals_enabled? end |