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

Instance Method Details

#approvalApproval

Retrieve approval record for the creation event.

Returns:



10
11
12
# File 'lib/acts_as_approvable/model/create_instance_methods.rb', line 10

def approval
  approvals.find_by_event('create')
end

#approval_stateString

Get the approval state of the current record from either the local state field or, if no state field exists, the creation approval object.

Returns:

  • (String)

    one of ‘’pending’‘, `’approved`‘ or `’rejected’‘.



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!

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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!

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Parameters:

  • state (String)

    one of ‘’pending’‘, `’approved`‘ or `’rejected’‘.



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