class Runcible::Instance

Attributes

config[R]
extensions[RW]
resources[RW]

Public Class Methods

extension_classes() click to toggle source
# File lib/runcible/instance.rb, line 49
def extension_classes
  @@extension_classes ||= gather_classes('extensions')
  @@extension_classes
end
new(config = {}) click to toggle source

Initialize a Runcible instance

@param [Hash] config @option config [String] :user Pulp username @option config [String] :oauth Oauth credentials @option config [Hash] :headers Additional headers e.g. content-type => “application/json” @option config [String] :url Scheme and hostname for the pulp server e.g. localhost/ @option config [String] :api_path URL path for the api e.g. pulp/api/v2/ @option config [String] :timeout Timeout in seconds for the connection (defaults to rest client's default) @option config [String] :open_timeout timeout in seconds for the connection

to open(defaults to rest client's default)

@option config [Hash] :http_auth Needed when using simple http auth @option http_auth [String] :password The password to use for simple auth

# File lib/runcible/instance.rb, line 19
def initialize(config = {})
  @config = {
    :api_path   => '/pulp/api/v2/',
    :url        => 'https://localhost',
    :user       => '',
    :http_auth  => {:password => {} },
    :headers    => {:content_type => 'application/json',
                    :accept       => 'application/json'},
    :logging    => {}
  }.merge(config).with_indifferent_access

  initialize_wrappers
end
resource_classes() click to toggle source

rubocop:disable Style/ClassVars

# File lib/runcible/instance.rb, line 44
def resource_classes
  @@resource_classes ||= gather_classes('resources')
  @@resource_classes
end

Private Class Methods

gather_classes(type) click to toggle source
# File lib/runcible/instance.rb, line 56
def gather_classes(type)
  const = Runcible
  const = const.const_get(type.camelize)
  path = File.dirname(__FILE__) + "/#{type}/*.rb"
  base_names = Dir.glob(path).map { |f| File.basename(f, '.rb') }
  base_names.map { |name| const.const_get(name.camelize) }
end

Public Instance Methods

update_config(key, value) click to toggle source

Update an existing config value @param [String, Symbol] key The key of the config to update @param [Object] value The value of the config to update

# File lib/runcible/instance.rb, line 36
def update_config(key, value)
  @config[key] = value
end

Private Instance Methods

accessible_class(class_object) click to toggle source
# File lib/runcible/instance.rb, line 82
def accessible_class(class_object)
  #converts a class (Runcible::Resources::ConsumerGroup) to a user friendly name:
  #  (e.g. consumer_group)
  class_object.name.split('::').last.underscore
end
initialize_wrappers() click to toggle source
# File lib/runcible/instance.rb, line 67
def initialize_wrappers
  self.resources = Wrapper.new('resources')
  self.extensions = Wrapper.new('extensions')

  self.class.resource_classes.each do |runcible_class|
    instance = runcible_class.new(@config)
    self.resources.set_instance(accessible_class(runcible_class), instance)
  end

  self.class.extension_classes.each do |runcible_class|
    instance = runcible_class.new(@config)
    self.extensions.set_instance(accessible_class(runcible_class), instance)
  end
end