forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_factory.rb
More file actions
31 lines (25 loc) · 762 Bytes
/
Copy pathapi_factory.rb
File metadata and controls
31 lines (25 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# encoding: utf-8
require 'github_api/core_ext/hash'
module Github
class ApiFactory
# Instantiates a new github api object
#
def self.new(klass, options={}, &block)
return create_instance(klass, options, &block) if klass
raise ArgumentError, 'must provide API class to be instantiated'
end
# Passes configuration options to instantiated class
#
def self.create_instance(klass, options, &block)
options.symbolize_keys!
convert_to_constant(klass.to_s).new options, &block
end
# Convert name to constant
#
def self.convert_to_constant(classes)
classes.split('::').inject(Github) do |constant, klass|
constant.const_get klass
end
end
end # ApiFactory
end # Github