Class: HammerCLI::Output::Adapter::Json
- Inherits:
-
TreeStructure
- Object
- Abstract
- TreeStructure
- HammerCLI::Output::Adapter::Json
- Defined in:
- lib/hammer_cli/output/adapter/json.rb
Instance Method Summary collapse
- #print_collection(fields, collection) ⇒ Object
- #print_message(msg, msg_params = {}) ⇒ Object
- #print_record(fields, record) ⇒ Object
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
#print_collection(fields, collection) ⇒ Object
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 |
#print_message(msg, msg_params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hammer_cli/output/adapter/json.rb', line 14 def (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 |
#print_record(fields, record) ⇒ Object
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 |