PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/octokit.rb

http://github.com/pengwynn/octokit
Ruby | 59 lines | 38 code | 11 blank | 10 comment | 7 complexity | 0c0089f1cd44b34ce209dfbece37bacc MD5 | raw file
 1require 'octokit/client'
 2require 'octokit/enterprise_admin_client'
 3require 'octokit/enterprise_management_console_client'
 4require 'octokit/default'
 5
 6# Ruby toolkit for the GitHub API
 7module Octokit
 8
 9  class << self
10    include Octokit::Configurable
11
12    # API client based on configured options {Configurable}
13    #
14    # @return [Octokit::Client] API wrapper
15    def client
16      return @client if defined?(@client) && @client.same_options?(options)
17      @client = Octokit::Client.new(options)
18    end
19
20    # EnterpriseAdminClient client based on configured options {Configurable}
21    #
22    # @return [Octokit::EnterpriseAdminClient] API wrapper
23    def enterprise_admin_client
24      return @enterprise_admin_client if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
25      @enterprise_admin_client = Octokit::EnterpriseAdminClient.new(options)
26    end
27
28    # EnterpriseManagementConsoleClient client based on configured options {Configurable}
29    #
30    # @return [Octokit::EnterpriseManagementConsoleClient] API wrapper
31    def enterprise_management_console_client
32      return @enterprise_management_console_client if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
33      @enterprise_management_console_client = Octokit::EnterpriseManagementConsoleClient.new(options)
34    end
35
36    private
37
38    def respond_to_missing?(method_name, include_private=false)
39      client.respond_to?(method_name, include_private) ||
40      enterprise_admin_client.respond_to?(method_name, include_private) ||
41      enterprise_management_console_client.respond_to?(method_name, include_private)
42    end
43
44    def method_missing(method_name, *args, &block)
45      if client.respond_to?(method_name)
46        return client.send(method_name, *args, &block)
47      elsif enterprise_admin_client.respond_to?(method_name)
48        return enterprise_admin_client.send(method_name, *args, &block)
49      elsif enterprise_management_console_client.respond_to?(method_name)
50        return enterprise_management_console_client.send(method_name, *args, &block)
51      end
52
53      super
54    end
55
56  end
57end
58
59Octokit.setup