Module: ActsAsApprovable::Model::CreateInstanceMethods
- Defined in:
- lib/acts_as_approvable/model/create_instance_methods.rb
Overview
Instance methods that apply to the ‘:create` event specifically.
Instance Method Summary collapse
-
#approval ⇒ Approval
Retrieve approval record for the creation event.
-
#approval_state ⇒ String
Get the approval state of the current record from either the local state field or, if no state field exists, the creation approval object.
-
#approve! ⇒ Boolean
Approves the record through Approval#approve!.
-
#approved? ⇒ Boolean
Returns true if the record has been approved.
-
#pending? ⇒ Boolean
Returns true if the record is pending approval.
-
#reject! ⇒ Boolean
Rejects the record through Approval#reject!.
-
#rejected? ⇒ Boolean
Returns true if the record has been rejected.
- #reset! ⇒ Object
-
#set_approval_state(state) ⇒ Object
Set the records local approval state.
Instance Method Details
#approval ⇒ Approval
Retrieve approval record for the creation event.
10 11 12 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 10 def approval approvals.find_by_event('create') end |
#approval_state ⇒ String
Get the approval state of the current record from either the local state field or, if no state field exists, the creation approval object.
19 20 21 22 23 24 25 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 19 def approval_state if self.class.approvable_field send(self.class.approvable_field) elsif approval.present? approval.state end end |
#approve! ⇒ Boolean
Approves the record through Approval#approve!
58 59 60 61 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 58 def approve! return unless approvable_on?(:create) && approval.present? approval.approve! end |
#approved? ⇒ Boolean
Returns true if the record has been approved.
44 45 46 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 44 def approved? approval_state.present? ? approval_state == 'approved' : approval.try(:approved?) end |
#pending? ⇒ Boolean
Returns true if the record is pending approval.
38 39 40 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 38 def pending? approval_state.present? ? approval_state == 'pending' : approval.try(:pending?) end |
#reject! ⇒ Boolean
Rejects the record through Approval#reject!
67 68 69 70 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 67 def reject! return unless approvable_on?(:create) && approval.present? approval.reject! end |
#rejected? ⇒ Boolean
Returns true if the record has been rejected.
50 51 52 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 50 def rejected? approval_state.present? ? approval_state == 'rejected' : approval.try(:rejected?) end |
#reset! ⇒ Object
72 73 74 75 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 72 def reset! return unless approvable_on?(:create) && approval.present? approval.reset! end |
#set_approval_state(state) ⇒ Object
Set the records local approval state.
31 32 33 34 |
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 31 def set_approval_state(state) return unless self.class.approvable_field send("#{self.class.approvable_field}=".to_sym, state) end |