Sha256: 6152115f273c3dd12fba453dd2fe1998387588f1fb58fec09c082d4b401e2a14

Contents?: true

Size: 790 Bytes

Versions: 1

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true
require 'bitbucket_rest_api/core_ext/hash'

module BitBucket
  class ApiFactory
    # Instantiates a new bitbucket api object
    def self.new(klass, options = {})
      return create_instance(klass, options) if klass

      raise ArgumentError, 'must provide klass to be instantiated'
    end

    # Passes configuration options to instantiated class
    def self.create_instance(klass, options)
      options.symbolize_keys!
      instance = convert_to_constant(klass.to_s).new options
      BitBucket.api_client = instance
      instance
    end

    def self.convert_to_constant(classes)
      constant = BitBucket
      classes.split('::').each do |klass|
        constant = constant.const_get klass
      end
      constant
    end
  end
end # BitBucket

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitbuckets-0.2.0 lib/bitbucket_rest_api/api_factory.rb