Class: HammerCLIForeman::Output::Formatters::SingleReferenceFormatter

Inherits:
HammerCLI::Output::Formatters::FieldFormatter
  • Object
show all
Defined in:
lib/hammer_cli_foreman/output/formatters.rb

Instance Method Summary collapse

Instance Method Details

#format(resource, field_params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 10

def format(resource, field_params={})
  return "" if resource.nil?

  key = field_params[:key]
  display_field = field_params[:display_field] || 'name'

  id_key = "#{key}_id"
  display_key = "#{key}_#{display_field}"

  name = resource[display_key.to_sym] || resource[display_key]
  id = resource[id_key.to_sym] || resource[id_key]

  context = field_params[:context] || {}

  out = "#{name}"
  out += " (id: #{id})" if context[:show_ids] && id
  out
end

#tagsObject



6
7
8
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 6

def tags
  [:flat]
end