Module: ActsAsApprovable::Model::InstanceMethods
- Defined in:
- lib/acts_as_approvable/model/instance_methods.rb
Overview
Instance methods that apply to both ‘:update` and `:create` events.
Instance Method Summary collapse
-
#after_approve(approval) ⇒ Object
A filter that is run after the record has been approved.
-
#after_reject(approval) ⇒ Object
A filter that is run after the record has been rejected.
-
#approvable_on?(event) ⇒ Boolean
Returns true if the model is configured to use the approval queue on the given event (‘:create` or `:update`).
-
#approvals_disabled? ⇒ Boolean
Returns the inverse of ‘#approvals_enabled?`.
-
#approvals_enabled? ⇒ Boolean
Returns true if the approval queue is active at both the local and global level.
-
#approvals_off ⇒ Object
Turn off approvals for this instance.
-
#approvals_on ⇒ Object
Turn on approvals for this instance.
-
#approvals_on? ⇒ Boolean
Returns true if the approval queue is on for this instance.
-
#before_approve(approval) ⇒ Object
A filter that is run before the record can be approved.
-
#before_reject(approval) ⇒ Object
A filter that is run before the record can be rejected.
-
#destroy_without_approval ⇒ Object
:nodoc:.
-
#destroy_without_approval! ⇒ Object
:nodoc:.
-
#global_approvals_on? ⇒ Boolean
Returns true if the approval queue is on globally.
-
#model_approvals_on? ⇒ Boolean
Returns true if the approval queue is on for this model.
-
#save_without_approval(*args) ⇒ Object
:nodoc:.
-
#save_without_approval!(*args) ⇒ Object
:nodoc:.
-
#without_approval(&block) ⇒ Object
Execute a code block while the approval queue is temporarily disabled.
Instance Method Details
#after_approve(approval) ⇒ Object
A filter that is run after the record has been approved.
63 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 63 def after_approve(approval); end |
#after_reject(approval) ⇒ Object
A filter that is run after the record has been rejected.
72 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 72 def after_reject(approval); end |
#approvable_on?(event) ⇒ Boolean
Returns true if the model is configured to use the approval queue on the given event (‘:create` or `:update`).
52 53 54 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 52 def approvable_on?(event) self.class.approvable_on?(event) end |
#approvals_disabled? ⇒ Boolean
Returns the inverse of ‘#approvals_enabled?`
15 16 17 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 15 def approvals_disabled? not approvals_enabled? end |
#approvals_enabled? ⇒ Boolean
Returns true if the approval queue is active at both the local and global level. Note that the global level supercedes the local level.
9 10 11 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 9 def approvals_enabled? global_approvals_on? and model_approvals_on? and approvals_on? end |
#approvals_off ⇒ Object
Turn off approvals for this instance.
21 22 23 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 21 def approvals_off @approvals_disabled = true end |
#approvals_on ⇒ Object
Turn on approvals for this instance.
27 28 29 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 27 def approvals_on @approvals_disabled = false end |
#approvals_on? ⇒ Boolean
Returns true if the approval queue is on for this instance.
33 34 35 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 33 def approvals_on? not @approvals_disabled end |
#before_approve(approval) ⇒ Object
A filter that is run before the record can be approved. Returning false stops the approval process from completing.
59 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 59 def before_approve(approval); end |
#before_reject(approval) ⇒ Object
A filter that is run before the record can be rejected. Returning false stops the rejection process from completing.
68 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 68 def before_reject(approval); end |
#destroy_without_approval ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 93 def destroy_without_approval #:nodoc: without_approval { |i| destroy } end |
#destroy_without_approval! ⇒ Object
:nodoc:
97 98 99 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 97 def destroy_without_approval! #:nodoc: without_approval { |i| destroy! } end |
#global_approvals_on? ⇒ Boolean
Returns true if the approval queue is on globally.
45 46 47 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 45 def global_approvals_on? ActsAsApprovable.enabled? end |
#model_approvals_on? ⇒ Boolean
Returns true if the approval queue is on for this model.
39 40 41 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 39 def model_approvals_on? self.class.approvals_on? end |
#save_without_approval(*args) ⇒ Object
:nodoc:
85 86 87 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 85 def save_without_approval(*args) #:nodoc: without_approval { |i| save(*args) } end |
#save_without_approval!(*args) ⇒ Object
:nodoc:
89 90 91 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 89 def save_without_approval!(*args) #:nodoc: without_approval { |i| save!(*args) } end |
#without_approval(&block) ⇒ Object
Execute a code block while the approval queue is temporarily disabled. The queue state will be returned to it’s previous value, either on or off.
77 78 79 80 81 82 83 |
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 77 def without_approval(&block) enable = approvals_on? # If we use #approvals_enabled? the global state might be incorrectly applied. approvals_off yield(self) ensure approvals_on if enable end |