Class: Github::API::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/github_api2/api/factory.rb

Class Method Summary collapse

Class Method Details

.convert_to_constant(classes) ⇒ Object

Convert name to constant



25
26
27
28
29
# File 'lib/github_api2/api/factory.rb', line 25

def self.convert_to_constant(classes)
  classes.split('::').inject(Github) do |constant, klass|
    constant.const_get klass
  end
end

.create_instance(klass, options, &block) ⇒ Object

Passes configuration options to instantiated class



18
19
20
21
# File 'lib/github_api2/api/factory.rb', line 18

def self.create_instance(klass, options, &block)
  options.symbolize_keys!
  convert_to_constant(klass.to_s).new options, &block
end

.new(klass, options = {}, &block) ⇒ Object

Instantiates a new github api object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/github_api2/api/factory.rb', line 11

def self.new(klass, options={}, &block)
  return create_instance(klass, options, &block) if klass
  raise ArgumentError, 'must provide API class to be instantiated'
end