Module: Pry::Octokit

Defined in:
lib/pry/octokit.rb,
lib/pry/octokit/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.clientObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pry/octokit.rb', line 9

def client
  @client ||= (
    conf = YAML.load_file(File.expand_path("~/.config/hub"))
    token = conf['github.com'].first['oauth_token']
    ::Octokit::Client.new(access_token: token).tap do |client|
      if debug?
        client.middleware = Faraday::RackBuilder.new do |builder|
          builder.use ::Octokit::Middleware::FollowRedirects
          builder.use ::Octokit::Response::RaiseError
          builder.use ::Octokit::Response::FeedParser
          builder.response :logger
          builder.adapter Faraday.default_adapter
        end
      end
    end
  )
end

.debug?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/pry/octokit.rb', line 27

def debug?
  ENV['PRY_OCTOKIT_DEBUG']
end

.parse_options(options) ⇒ Object



53
54
55
56
57
# File 'lib/pry/octokit.rb', line 53

def parse_options(options)
  eval("{#{options}}").tap do |opt|
    opt[:method] ||= :get
  end
end

.run(path, _pry_) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pry/octokit.rb', line 31

def run(path, _pry_)
  path, options = path.split(' ', 2)
  path = eval %Q!"#{path}"!
  options = parse_options options
  method = options.delete :method
  c = client
  auto_paginate = options.delete :auto_paginate
  if auto_paginate
    puts "With auto_paginate" if debug?
    c = c.dup
    c.auto_paginate = true
  end
  resp =
    if auto_paginate
      c.__send__ :paginate, path, options
    else
      c.__send__ :request, method, path, options
    end
  _pry_.last_result = resp
  _pry_.show_result resp
end