Class: HammerCLI::Output::Adapter::Json

Inherits:
TreeStructure show all
Defined in:
lib/hammer_cli/output/adapter/json.rb

Instance Method Summary collapse

Methods inherited from TreeStructure

#initialize, #prepare_collection

Methods inherited from Abstract

#initialize, #paginate_by_default?, #print_error, #tags

Constructor Details

This class inherits a constructor from HammerCLI::Output::Adapter::TreeStructure

Instance Method Details



9
10
11
12
# File 'lib/hammer_cli/output/adapter/json.rb', line 9

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


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hammer_cli/output/adapter/json.rb', line 14

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


4
5
6
7
# File 'lib/hammer_cli/output/adapter/json.rb', line 4

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