Sha256: 034b4f652e8563773ee8ff980f4db403baed4b3ad69372c5fbb80e2a04959e8e

Contents?: true

Size: 823 Bytes

Versions: 2

Compression:

Stored size: 823 Bytes

Contents

# encoding: utf-8

require 'github_api2/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

2 entries across 2 versions & 1 rubygems

Version Path
github_api2-1.0.1 lib/github_api2/api/factory.rb
github_api2-1.0.0 lib/github_api2/api/factory.rb