Sha256: 5c9368d14367ccc71c6126dab9971b6dd1a596413017a19932cd21288a3b0ef3

Contents?: true

Size: 781 Bytes

Versions: 5

Compression:

Stored size: 781 Bytes

Contents

# encoding: utf-8

require 'bitbucket_rest_api/core_ext/hash'

module BitBucket
  class API
    class Factory

      # Instantiates a new bitbucket api object
      def self.new(klass, options={}, &block)
        return create_instance(klass, options, &block) if klass
        raise ArgumentError, 'must provide klass 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

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

    end # Factory
  end # Api
end # BitBucket

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
codenamev_bitbucket_api-0.4.1 lib/bitbucket_rest_api/api/factory.rb
codenamev_bitbucket_api-0.4.0 lib/bitbucket_rest_api/api/factory.rb
reenhanced_bitbucket_api-0.3.2 lib/bitbucket_rest_api/api/factory.rb
reenhanced_bitbucket_api-0.3.1 lib/bitbucket_rest_api/api/factory.rb
reenhanced_bitbucket_api-0.3.0 lib/bitbucket_rest_api/api/factory.rb