Class: Rails::Approvals::SlackResponse

Inherits:
Object
  • Object
show all
Defined in:
app/models/rails/approvals/slack_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ SlackResponse

Returns a new instance of SlackResponse.



7
8
9
10
# File 'app/models/rails/approvals/slack_response.rb', line 7

def initialize(payload)
  @payload = payload
  @responder = payload['user']['username']
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'app/models/rails/approvals/slack_response.rb', line 4

def payload
  @payload
end

#responderObject (readonly)

Returns the value of attribute responder.



5
6
7
# File 'app/models/rails/approvals/slack_response.rb', line 5

def responder
  @responder
end

Instance Method Details

#performObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/rails/approvals/slack_response.rb', line 12

def perform
  payload['actions'].all? do |action|
    request = GlobalID::Locator.locate(action['block_id'])

    case action['value']
    when 'approve'
      request.update!(
        responder: responder,
        state: :approved,
      )
    when 'deny'
      request.update!(
        responder: responder,
        state: :denied,
      )
    end
  end
end