Parent

Methods

Class/Module Index [+]

Quicksearch

HammerCLIForeman::Output::Formatters::ReferenceFormatter

Public Instance Methods

format(reference, field_params={}) click to toggle source
# File lib/hammer_cli_foreman/output/formatters.rb, line 38
def format(reference, field_params={})
  return "" if reference.nil?

  id_key = field_params[:id_key] || :id
  name_key = field_params[:name_key] || :name

  name = reference[name_key] || reference[name_key.to_s]
  id = reference[id_key] || reference[id_key.to_s]

  context = field_params[:context] || {}

  details = field_params[:details] || []
  details = [details] unless details.is_a? Array
  values = details.collect do |key|
    reference[key] || reference[key.to_s]
  end
  values << "id: #{id}" if context[:show_ids]

  if values.empty?
    "#{name}" if name
  else
    "#{name} (#{values.join(', ')})" if name && !values.empty?
  end
end
tags() click to toggle source
# File lib/hammer_cli_foreman/output/formatters.rb, line 34
def tags
  [:flat]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.