Class: Github::API::Factory
- Inherits:
-
Object
- Object
- Github::API::Factory
- Defined in:
- lib/github_api2/api/factory.rb
Class Method Summary collapse
-
.convert_to_constant(classes) ⇒ Object
Convert name to constant.
-
.create_instance(klass, options, &block) ⇒ Object
Passes configuration options to instantiated class.
-
.new(klass, options = {}, &block) ⇒ Object
Instantiates a new github api object.
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, , &block) .symbolize_keys! convert_to_constant(klass.to_s).new , &block end |
.new(klass, options = {}, &block) ⇒ Object
Instantiates a new github api object
11 12 13 14 |
# File 'lib/github_api2/api/factory.rb', line 11 def self.new(klass, ={}, &block) return create_instance(klass, , &block) if klass raise ArgumentError, 'must provide API class to be instantiated' end |