Method: Github::API.namespace

Defined in:
lib/github_api2/api.rb

.namespace(*names) ⇒ self

Defines a namespace

Examples:

namespace :scopes

Parameters:

  • names (Array[Symbol])

    the name for the scope

Returns:

  • (self)


322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/github_api2/api.rb', line 322

def self.namespace(*names)
  options = names.last.is_a?(Hash) ? names.pop : {}
  names   = names.map(&:to_sym)
  name    = names.pop

  if public_method_defined?(name)
    raise ArgumentError, "namespace '#{name}' is already defined"
  end

  class_name = extract_class_name(name, options)

  define_method(name) do |*args, &block|
    options = args.last.is_a?(Hash) ? args.pop : {}
    API::Factory.new(class_name, current_options.merge(options), &block)
  end
end