Sha256: dc58960b6f9ebde4cf76b6694184bfa89828fcd256bb31341d3c7bf421551a5c

Contents?: true

Size: 848 Bytes

Versions: 2

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

module Logux
  class Add
    attr_reader :client, :version, :password

    def initialize(client: Logux::Client.new,
                   version: Logux::PROTOCOL_VERSION,
                   password: Logux.configuration.password)
      @client = client
      @version = version
      @password = password
    end

    def call(commands)
      return if commands.empty?

      prepared_data = prepare_data(commands)
      Logux.logger.debug("Logux add: #{prepared_data}")
      client.post(prepared_data)
    end

    private

    def prepare_data(commands)
      {
        version: PROTOCOL_VERSION,
        password: password,
        commands: commands.map do |command|
          action = command.first
          meta = command[1]
          ['action', action, meta || Meta.new]
        end
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
logux-rack-0.1.0 lib/logux/add.rb
logux_rails-0.1.0 lib/logux/add.rb