Module: GH

Extended by:
SingleForwardable
Defined in:
lib/gh.rb,
lib/gh/case.rb,
lib/gh/cache.rb,
lib/gh/error.rb,
lib/gh/stack.rb,
lib/gh/remote.rb,
lib/gh/version.rb,
lib/gh/wrapper.rb,
lib/gh/parallel.rb,
lib/gh/response.rb,
lib/gh/normalizer.rb,
lib/gh/pagination.rb,
lib/gh/lazy_loader.rb,
lib/gh/token_check.rb,
lib/gh/custom_limit.rb,
lib/gh/merge_commit.rb,
lib/gh/link_follower.rb,
lib/gh/instrumentation.rb,
lib/gh/nested_resources.rb,
lib/gh/response_wrapper.rb,
lib/gh/response_x_header_formatter.rb

Defined Under Namespace

Modules: Case Classes: Cache, CustomLimit, Error, Instrumentation, LazyLoader, LinkFollower, MergeCommit, NestedResources, Normalizer, Pagination, Parallel, Remote, Response, ResponseWrapper, ResponseXHeaderFormatter, Stack, TokenCheck, TokenInvalid, Wrapper

Constant Summary collapse

DefaultStack =
Stack.new do
  use Instrumentation
  use Parallel
  use TokenCheck
  use Pagination
  use LinkFollower
  use MergeCommit
  use LazyLoader
  use Normalizer
  use CustomLimit
  use Remote
end
VERSION =

Public: Library version.

'0.21.0'

Class Method Summary collapse

Class Method Details

.currentObject



52
53
54
# File 'lib/gh.rb', line 52

def self.current
  Thread.current[:GH] ||= DefaultStack.new
end

.current=(backend) ⇒ Object



56
57
58
# File 'lib/gh.rb', line 56

def self.current=(backend)
  Thread.current[:GH] = backend
end

.Error(conditions) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gh/error.rb', line 60

def self.Error(conditions)
  Module.new do
    define_singleton_method(:===) do |exception|
      return false unless exception.is_a?(Error) && !exception.info.nil?

      # rubocop:disable Style/CaseEquality
      conditions.all? { |k, v| v === exception.info[k] }
      # rubocop:enable Style/CaseEquality
    end
  end
end

.method_missing(*args, &block) ⇒ Object



64
65
66
# File 'lib/gh.rb', line 64

def self.method_missing(*args, &block)
  current.public_send(*args, &block)
end

.respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/gh.rb', line 68

def self.respond_to_missing?(method, *)
  super
end

.set(options) ⇒ Object



47
48
49
50
# File 'lib/gh.rb', line 47

def self.set(options)
  Thread.current[:GH] = nil
  DefaultStack.options.merge! options
end

.with(backend) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gh.rb', line 27

def self.with(backend)
  if backend.is_a?(Hash)
    @options ||= {}
    options = @options
    @options = @options.merge(backend)
    backend = DefaultStack.build(@options)
  end

  if block_given?
    was = current
    self.current = backend
    yield
  else
    backend
  end
ensure
  @options = options if options
  self.current = was if was
end