class Logux::Process::Action

Attributes

chunk[R]
stop_process[RW]
stream[R]

Public Class Methods

new(stream:, chunk:) click to toggle source
# File lib/logux/process/action.rb, line 9
def initialize(stream:, chunk:)
  @stream = stream
  @chunk = chunk
end

Public Instance Methods

action_from_chunk() click to toggle source
# File lib/logux/process/action.rb, line 19
def action_from_chunk
  @action_from_chunk ||= chunk[:action]
end
call() click to toggle source
# File lib/logux/process/action.rb, line 14
def call
  process_authorization!
  process_action!
end
meta_from_chunk() click to toggle source
# File lib/logux/process/action.rb, line 23
def meta_from_chunk
  @meta_from_chunk ||= chunk[:meta]
end
stop_process!() click to toggle source
# File lib/logux/process/action.rb, line 31
def stop_process!
  @stop_process = true
end
stop_process?() click to toggle source
# File lib/logux/process/action.rb, line 27
def stop_process?
  @stop_process ||= false
end

Private Instance Methods

process_action!() click to toggle source
# File lib/logux/process/action.rb, line 37
def process_action!
  return if stop_process?

  action_caller = Logux::ActionCaller.new(
    action: action_from_chunk,
    meta: meta_from_chunk
  )

  stream.write(action_caller.call!.format)
end
process_authorization!() click to toggle source
# File lib/logux/process/action.rb, line 48
def process_authorization!
  policy_caller = Logux::PolicyCaller.new(action: action_from_chunk,
                                          meta: meta_from_chunk)
  policy_check = policy_caller.call!
  status = policy_check ? :approved : :forbidden
  stream.write([status, meta_from_chunk.id])
  return stream.write(',') if policy_check

  stop_process!
end