Class: PlanMyStuff::Approval

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


37
38
39
# File 'lib/plan_my_stuff/approval.rb', line 37

def approved?
  status == 'approved'
end

#approved_atDateTime?

Returns timestamp when status flipped to “approved”.

Returns:

  • (DateTime, nil)

    timestamp when status flipped to “approved”



26
# File 'lib/plan_my_stuff/approval.rb', line 26

attribute :approved_at, :datetime

#hashInteger

Returns:

  • (Integer)


76
77
78
# File 'lib/plan_my_stuff/approval.rb', line 76

def hash
  [user_id, status].hash
end

#pending?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/plan_my_stuff/approval.rb', line 32

def pending?
  status == 'pending'
end

#statusString

Returns “pending” or “approved”.

Returns:

  • (String)

    “pending” or “approved”



24
# File 'lib/plan_my_stuff/approval.rb', line 24

attribute :status, :string, default: 'pending'

#to_hHash

Returns:

  • (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

#userObject?

Lazy-resolves the app-side user for this approval. Not memoized – PlanMyStuff::UserResolver owns caching.

Returns:

  • (Object, nil)


46
47
48
# File 'lib/plan_my_stuff/approval.rb', line 46

def user
  PlanMyStuff::UserResolver.resolve(user_id)
end

#user_idInteger

Returns app-side user id of the required approver.

Returns:

  • (Integer)

    app-side user id of the required approver



22
# File 'lib/plan_my_stuff/approval.rb', line 22

attribute :user_id, :integer