Class: HammerCLIForeman::Output::Formatters::ReferenceFormatter
- Inherits:
-
HammerCLI::Output::Formatters::FieldFormatter
- Object
- HammerCLI::Output::Formatters::FieldFormatter
- HammerCLIForeman::Output::Formatters::ReferenceFormatter
- Defined in:
- lib/hammer_cli_foreman/output/formatters.rb
Instance Method Summary collapse
-
#format(data, field_params = {}) ⇒ Object
Parameters: :display_field_key - key where the formmatter will look for the main field to display, default is :name :details - detail fields to be displayed example format: :details => [ { :label => _(‘Type’), :key => :provider_friendly_name, :structured_label => _(‘Type’) }, { :label => _(‘Id’), :key => :id } ].
- #required_features ⇒ Object
Instance Method Details
#format(data, field_params = {}) ⇒ Object
Parameters: :display_field_key - key where the formmatter will look for the main field to display, default is :name :details - detail fields to be displayed
example format:
:details => [
{ :label => _('Type'), :key => :provider_friendly_name, :structured_label => _('Type') },
{ :label => _('Id'), :key => :id }
]
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 16 def format(data, field_params={}) return "" if data.nil? name = get_value(data, field_params[:display_field_key] || :name) context = field_params[:context] || {} details = format_details(data, field_params[:details] || [], context[:show_ids]) if details.empty? "#{name}" if name else "#{name} (#{details.join(', ')})" if name end end |
#required_features ⇒ Object
4 5 6 |
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 4 def required_features %i[serialized] end |