Sha256: 075eb74bbf883b720c8b084717a44b33e4b39275e76b09160083a31a095ebdcf

Contents?: true

Size: 771 Bytes

Versions: 11

Compression:

Stored size: 771 Bytes

Contents

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

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

    def print_collection(fields, collection)
      result = prepare_collection(fields, collection)
      puts JSON.pretty_generate(result)
    end

    def print_message(msg, msg_params={})
      id = msg_params["id"] || msg_params[:id]
      name = msg_params["name"] || msg_params[:name]

      data = {
        :message => msg.format(msg_params)
      }
      data[:id] = id unless id.nil?
      data[:name] = name unless name.nil?

      puts JSON.pretty_generate(data)
    end

  end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hammer_cli-0.12.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.11.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.10.2 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.10.1 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.10.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.9.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.8.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.7.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.6.1 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.6.0 lib/hammer_cli/output/adapter/json.rb
hammer_cli-0.5.1 lib/hammer_cli/output/adapter/json.rb