Class: PlanMyStuff::Approval
- Inherits:
-
Object
- Object
- PlanMyStuff::Approval
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Serializers::JSON
- Defined in:
- lib/plan_my_stuff/approval.rb
Overview
Value object representing a single manager approval on an Issue. Persisted in IssueMetadata#approvals and returned from Issue.request_approvals!, Issue.approve!, Issue.reject!, and Issue.revoke_approval!.
Mirrors PlanMyStuff::Link: ActiveModel::Attributes-backed, with Serializers::JSON for round-trip through the metadata blob.
Constant Summary collapse
- STATUSES =
%w[pending approved rejected].freeze
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Two approvals are equal when they track the same user AND carry the same status.
- #approved? ⇒ Boolean
-
#approved_at ⇒ DateTime?
Timestamp when status flipped to “approved”.
- #hash ⇒ Integer
- #pending? ⇒ Boolean
- #rejected? ⇒ Boolean
-
#rejected_at ⇒ DateTime?
Timestamp when status flipped to “rejected”.
-
#status ⇒ String
“pending”, “approved”, or “rejected”.
- #to_h ⇒ Hash
-
#user ⇒ Object?
Lazy-resolves the app-side user for this approval.
-
#user_id ⇒ Integer
App-side user id of the required approver.
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Two approvals are equal when they track the same user AND carry the same status. A pending and an approved record for the same user are NOT equal – matters for set arithmetic during state transitions.
75 76 77 78 79 |
# File 'lib/plan_my_stuff/approval.rb', line 75 def ==(other) return false unless other.is_a?(PlanMyStuff::Approval) user_id == other.user_id && status == other.status end |
#approved? ⇒ Boolean
39 40 41 |
# File 'lib/plan_my_stuff/approval.rb', line 39 def approved? status == 'approved' end |
#approved_at ⇒ DateTime?
Returns timestamp when status flipped to “approved”.
26 |
# File 'lib/plan_my_stuff/approval.rb', line 26 attribute :approved_at, :datetime |
#hash ⇒ Integer
84 85 86 |
# File 'lib/plan_my_stuff/approval.rb', line 84 def hash [user_id, status].hash end |
#pending? ⇒ Boolean
34 35 36 |
# File 'lib/plan_my_stuff/approval.rb', line 34 def pending? status == 'pending' end |
#rejected? ⇒ Boolean
44 45 46 |
# File 'lib/plan_my_stuff/approval.rb', line 44 def rejected? status == 'rejected' end |
#rejected_at ⇒ DateTime?
Returns timestamp when status flipped to “rejected”.
28 |
# File 'lib/plan_my_stuff/approval.rb', line 28 attribute :rejected_at, :datetime |
#status ⇒ String
Returns “pending”, “approved”, or “rejected”.
24 |
# File 'lib/plan_my_stuff/approval.rb', line 24 attribute :status, :string, default: 'pending' |
#to_h ⇒ Hash
58 59 60 61 62 63 64 65 |
# File 'lib/plan_my_stuff/approval.rb', line 58 def to_h { user_id: user_id, status: status, approved_at: PlanMyStuff.format_time(approved_at), rejected_at: PlanMyStuff.format_time(rejected_at), } end |
#user ⇒ Object?
Lazy-resolves the app-side user for this approval. Not memoized – PlanMyStuff::UserResolver owns caching.
53 54 55 |
# File 'lib/plan_my_stuff/approval.rb', line 53 def user PlanMyStuff::UserResolver.resolve(user_id) end |
#user_id ⇒ Integer
Returns app-side user id of the required approver.
22 |
# File 'lib/plan_my_stuff/approval.rb', line 22 attribute :user_id, :integer |