Class: HammerCLI::Output::Adapter::TreeStructure

Inherits:
Abstract
  • Object
show all
Defined in:
lib/hammer_cli/output/adapter/tree_structure.rb

Direct Known Subclasses

Json, Yaml

Instance Method Summary collapse

Methods inherited from Abstract

#paginate_by_default?, #print_collection, #print_error, #print_message, #print_record

Constructor Details

#initialize(context = {}, formatters = {}) ⇒ TreeStructure

Returns a new instance of TreeStructure.



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

def initialize(context={}, formatters={})
  super
  @paginate_by_default = false
end

Instance Method Details

#prepare_collection(fields, collection) ⇒ Object



15
16
17
18
19
# File 'lib/hammer_cli/output/adapter/tree_structure.rb', line 15

def prepare_collection(fields, collection)
  collection.map do |element|
    render_fields(fields, element)
  end
end

#prepare_message(msg, msg_params = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hammer_cli/output/adapter/tree_structure.rb', line 21

def prepare_message(msg, msg_params = {})
  id = msg_params['id'] || msg_params[:id]
  name = msg_params['name'] || msg_params[:name]

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

#tagsObject



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

def tags
  [
    :data
  ]
end