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

Instance Method Details

#after_approve(approval) ⇒ Object

A filter that is run after the record has been approved.



53
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 53

def after_approve(approval); end

#after_reject(approval) ⇒ Object

A filter that is run after the record has been rejected.



62
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 62

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`).

Returns:

  • (Boolean)


42
43
44
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 42

def approvable_on?(event)
  self.class.approvable_on?(event)
end

#approvals_disabled?Boolean

Returns the inverse of ‘#approvals_enabled?`

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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_offObject



19
20
21
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 19

def approvals_off
  @approvals_disabled = true
end

#approvals_onObject



23
24
25
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 23

def approvals_on
  @approvals_disabled = false
end

#approvals_on?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 27

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.



49
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 49

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.



58
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 58

def before_reject(approval); end

#global_approvals_on?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 35

def global_approvals_on?
  ActsAsApprovable.enabled?
end

#model_approvals_on?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 31

def model_approvals_on?
  self.class.approvals_on?
end

#save_without_approval(*args) ⇒ Object



75
76
77
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 75

def save_without_approval(*args)
  without_approval { |i| save(*args) }
end

#save_without_approval!(*args) ⇒ Object



79
80
81
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 79

def save_without_approval!(*args)
  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.



67
68
69
70
71
72
73
# File 'lib/acts_as_approvable/model/instance_methods.rb', line 67

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