Class: BitBucket::API::Factory

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

Class Method Summary collapse

Class Method Details

.convert_to_constant(classes) ⇒ Object



21
22
23
24
25
# File 'lib/bitbucket_rest_api/api/factory.rb', line 21

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

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

Passes configuration options to instantiated class



16
17
18
19
# File 'lib/bitbucket_rest_api/api/factory.rb', line 16

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 bitbucket api object

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/bitbucket_rest_api/api/factory.rb', line 10

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