Sha256: dc3209e3fc32ed059f46f3a075efa7695fc5f96f32516be262d8933aaa150203

Contents?: true

Size: 914 Bytes

Versions: 1

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

class LoguxController < ActionController::Base
  include ActionController::Live

  def create
    logux_stream.write('[')
    Logux.verify_request_meta_data(meta_params)
    Logux.process_batch(stream: logux_stream, batch: command_params)
  rescue => ex
    handle_processing_errors(ex)
  ensure
    logux_stream.write(']')
    logux_stream.close
  end

  private

  def unsafe_params
    params.to_unsafe_h
  end

  def command_params
    unsafe_params.dig('commands')
  end

  def meta_params
    unsafe_params&.slice(:version, :password)
  end

  def logux_stream
    @logux_stream ||= Logux::Stream.new(response.stream)
  end

  def handle_processing_errors(exception)
    Logux.configuration.on_error.call(exception)
    Logux.logger.error("#{exception}\n#{exception.backtrace.join("\n")}")
  ensure
    logux_stream.write(Logux::ErrorRenderer.new(exception).message)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logux_rails-0.1.0 app/controllers/logux_controller.rb