Sha256: 87bd3e80491b6a304ecfc68687b248ac6b9bfdf456c82ebdeb78080c9eb6eab2

Contents?: true

Size: 986 Bytes

Versions: 28

Compression:

Stored size: 986 Bytes

Contents

module HammerCLI::Output::Adapter
  class Json < TreeStructure

    def print_record(fields, record)
      result = prepare_collection(fields, [record].flatten(1))
      output_stream.puts JSON.pretty_generate(result.first)
    end

    def print_collection(fields, collection, options = {})
      current_chunk = options[:current_chunk] || :single
      prepared = prepare_collection(fields, collection)
      result = JSON.pretty_generate(prepared)
      if current_chunk != :single
        result = if current_chunk == :first
                   result[0...-2] + ','
                 elsif current_chunk == :last
                   result[2..-1]
                 else
                   result[2...-2] + ','
                 end
      end
      output_stream.puts result
    end

    def print_message(msg, msg_params={})
      data = prepare_message(msg, msg_params)
      puts JSON.pretty_generate(data)
    end

  end

  HammerCLI::Output::Output.register_adapter(:json, Json)
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
hammer_cli-3.13.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.12.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.10.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.9.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.8.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.7.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.5.1 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.6.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.5.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.4.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.3.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.2.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.1.1 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.0.2 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.1.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.0.1 lib/hammer_cli/output/adapter/json.rb
hammer_cli-3.0.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-2.5.1 lib/hammer_cli/output/adapter/json.rb
hammer_cli-2.5.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-2.3.1 lib/hammer_cli/output/adapter/json.rb