Sha256: d005087e1f7e069a5ffef3982f906f1784cbb6cb1f4590cb893a1f7c3a8b28ba

Contents?: true

Size: 822 Bytes

Versions: 20

Compression:

Stored size: 822 Bytes

Contents

# encoding: utf-8

require 'github_api/core_ext/hash'

module Github
  class API
    class Factory

      # 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 # Factory
  end # Api
end # Github

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
github_api-0.19.0 lib/github_api/api/factory.rb
lingfennan-github_api-0.18.2 lib/github_api/api/factory.rb
github_api-0.18.2 lib/github_api/api/factory.rb
github_api-0.18.1 lib/github_api/api/factory.rb
github_api-0.17.0 lib/github_api/api/factory.rb
github_api-0.16.0 lib/github_api/api/factory.rb
github_api-0.15.0 lib/github_api/api/factory.rb
github_api-0.14.5 lib/github_api/api/factory.rb
github_api-0.14.4 lib/github_api/api/factory.rb
github_api-0.14.3 lib/github_api/api/factory.rb
github_api-0.14.2 lib/github_api/api/factory.rb
github_api-0.14.1 lib/github_api/api/factory.rb
github_api-0.14.0 lib/github_api/api/factory.rb
github_api-0.13.1 lib/github_api/api/factory.rb
github_api-0.13.0 lib/github_api/api/factory.rb
github_api-0.12.4 lib/github_api/api/factory.rb
github_api-0.12.3 lib/github_api/api/factory.rb
github_api-0.12.2 lib/github_api/api/factory.rb
github_api-0.12.1 lib/github_api/api/factory.rb
github_api-0.12.0 lib/github_api/api/factory.rb