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!, 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].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
-
#status ⇒ String
“pending” or “approved”.
- #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.
67 68 69 70 71 |
# File 'lib/plan_my_stuff/approval.rb', line 67 def ==(other) return false unless other.is_a?(PlanMyStuff::Approval) user_id == other.user_id && status == other.status end |
#approved? ⇒ Boolean
37 38 39 |
# File 'lib/plan_my_stuff/approval.rb', line 37 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
76 77 78 |
# File 'lib/plan_my_stuff/approval.rb', line 76 def hash [user_id, status].hash end |
#pending? ⇒ Boolean
32 33 34 |
# File 'lib/plan_my_stuff/approval.rb', line 32 def pending? status == 'pending' end |
#status ⇒ String
Returns “pending” or “approved”.
24 |
# File 'lib/plan_my_stuff/approval.rb', line 24 attribute :status, :string, default: 'pending' |
#to_h ⇒ Hash
51 52 53 54 55 56 57 |
# File 'lib/plan_my_stuff/approval.rb', line 51 def to_h { user_id: user_id, status: status, approved_at: approved_at&.iso8601, } end |
#user ⇒ Object?
Lazy-resolves the app-side user for this approval. Not memoized – PlanMyStuff::UserResolver owns caching.
46 47 48 |
# File 'lib/plan_my_stuff/approval.rb', line 46 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 |