Module: HrLite::Approvable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Expense, LeaveRequest
- Defined in:
- app/models/concerns/hr_lite/approvable.rb
Overview
Opts a model into the routed, multi-step approval flow — WITHOUT taking over what its decisions mean.
The model keeps its own approve! / reject!: those are the domain
actions, and for leave one of them credits a balance inside a row lock.
This concern only asks "is it this person's turn, and does their answer
settle it?" and hands back an outcome for the model to act on.
A subject type with no active flow behaves exactly as it did before — single decision, whoever holds the permission. That is what lets the four existing modules migrate one at a time instead of all at once.
Instance Method Summary collapse
- #approval_for(user) ⇒ Object
-
#approval_history ⇒ Object
The whole story, for the approval screen: who decided what, in order, including the rungs that were skipped and why.
- #approval_route ⇒ Object
-
#awaiting?(user) ⇒ Boolean
Whether this person is the one being waited on.
-
#pending_approvals ⇒ Object
The rows still waiting, newest rung first — what the show screen lists.
- #routed_for_approval? ⇒ Boolean
Instance Method Details
#approval_for(user) ⇒ Object
28 29 30 31 32 |
# File 'app/models/concerns/hr_lite/approvable.rb', line 28 def approval_for(user) return nil if user.nil? pending_approvals.detect { |approval| approval.answerable_by?(user) } end |
#approval_history ⇒ Object
The whole story, for the approval screen: who decided what, in order, including the rungs that were skipped and why.
40 |
# File 'app/models/concerns/hr_lite/approvable.rb', line 40 def approval_history = approvals.order(:position, :id) |
#approval_route ⇒ Object
21 |
# File 'app/models/concerns/hr_lite/approvable.rb', line 21 def approval_route = @approval_route ||= ApprovalRoute.new(self) |
#awaiting?(user) ⇒ Boolean
Whether this person is the one being waited on. Unrouted subjects fall back to the permission check the module already used.
36 |
# File 'app/models/concerns/hr_lite/approvable.rb', line 36 def awaiting?(user) = approval_for(user).present? |
#pending_approvals ⇒ Object
The rows still waiting, newest rung first — what the show screen lists.
26 |
# File 'app/models/concerns/hr_lite/approvable.rb', line 26 def pending_approvals = approvals.pending.order(:position) |
#routed_for_approval? ⇒ Boolean
23 |
# File 'app/models/concerns/hr_lite/approvable.rb', line 23 def routed_for_approval? = approval_route.routed? |