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
28
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 10

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

  key = field_params[:key]

  id_key = "#{key}_id"
  name_key = "#{key}_name"

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

  context = field_params[:context] || {}

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

#tagsObject



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

def tags
  [:flat]
end