module HammerCLIForeman

Constants

CONNECTION_NAME
RESOURCE_NAME_MAPPING

Public Class Methods

collection_to_common_format(data) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 39
def self.collection_to_common_format(data)
  if data.class <= Hash && data.has_key?('total') && data.has_key?('results')
    col = HammerCLI::Output::RecordCollection.new(data['results'],
      :total => data['total'],
      :subtotal => data['subtotal'],
      :page => data['page'],
      :per_page => data['per_page'],
      :search => data['search'],
      :sort_by => data['sort']['by'],
      :sort_order => data['sort']['order'])
  elsif data.class <= Hash
    col = HammerCLI::Output::RecordCollection.new(data)
  elsif data.class <= Array
    # remove object types. From [ { 'type' => { 'attr' => val } }, ... ]
    # produce [ { 'attr' => 'val' }, ... ]
    col = HammerCLI::Output::RecordCollection.new(data.map { |r| r.keys.length == 1 ? r[r.keys[0]] : r })
  else
    raise RuntimeError.new(_("Received data of unknown format."))
  end
  col
end
exception_handler_class() click to toggle source
# File lib/hammer_cli_foreman.rb, line 7
def self.exception_handler_class
  HammerCLIForeman::ExceptionHandler
end
foreman_api() click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 14
def self.foreman_api
  foreman_api_connection
end
foreman_api_connection() click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 88
def self.foreman_api_connection
  HammerCLI.context[:api_connection].create(CONNECTION_NAME) do
    HammerCLIForeman::Api::Connection.new(HammerCLI::Settings, Logging.logger['API'], HammerCLI::I18n.locale)
  end
end
foreman_resource(resource_name, options={}) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 27
def self.foreman_resource(resource_name, options={})
  begin
    foreman_resource!(resource_name, options)
  rescue NameError
    nil
  end
end
foreman_resource!(resource_name, options={}) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 18
def self.foreman_resource!(resource_name, options={})
  if options[:singular]
    resource_name = ApipieBindings::Inflector.pluralize(resource_name.to_s).to_sym
  else
    resource_name = resource_name.to_sym
  end
  foreman_api.resource(resource_name)
end
init_api_connection() click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 94
def self.init_api_connection
  foreman_api_connection
end
param_to_resource(param_name) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 35
def self.param_to_resource(param_name)
  HammerCLIForeman.foreman_resource(param_name.gsub(/_id[s]?$/, ""), :singular => true)
end
record_to_common_format(data) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 61
def self.record_to_common_format(data)
    data.class <= Hash && data.keys.length == 1 ? data[data.keys[0]] : data
end
version() click to toggle source
# File lib/hammer_cli_foreman/version.rb, line 2
def self.version
  @version ||= Gem::Version.new '0.15.0'
end