class Fasterer::Github::GhTraverser

Attributes

ignored_paths[R]
owner[R]
path[R]
repo[R]

Public Class Methods

new(owner, repo, path, ignored_paths) click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 6
def initialize(owner, repo, path, ignored_paths)
  @owner = owner
  @repo = repo
  @path = path.to_s
  @ignored_paths = ignored_paths.map { |i| i.chomp("/") }
end

Public Instance Methods

api_errors() click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 21
def api_errors
  @api_errors ||= []
end
collected_data() click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 17
def collected_data
  @collected_data ||= []
end
traverse() click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 13
def traverse
  catch(:rate_limit) { collect_data(path) }
end

Private Instance Methods

collect_data(path) click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 33
def collect_data(path)
  response = wrapper.contents(path)
  return store_api_error(response, path) unless response.code < 400
  parsed_response = response.parsed_response

  if parsed_response.is_a?(Hash)
    store_data(parsed_response)
  else
    parsed_response.each do |item|
      next if ignored_paths.include?(item['path'])
      next if item['type'] == 'file' && !ruby_file?(item['path'])
      collect_data(item['path'])
    end
  end
end
rate_limit_error?(response) click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 55
def rate_limit_error?(response)
  response.code == 403 && response.body =~ /rate limit exceeded/i
end
ruby_file?(file_name) click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 64
def ruby_file?(file_name)
  file_name =~ /\.rb$/
end
store_api_error(response, path) click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 49
def store_api_error(response, path)
  response_code = response.code
  api_errors << { code: response_code, msg_body: response.body, path: path }
  throw(:rate_limit) if rate_limit_error?(response)
end
store_data(response) click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 59
def store_data(response)
  file_data = { path: response['path'], content64: response['content'] }
  collected_data << file_data
end
wrapper() click to toggle source
# File lib/fasterer/github/gh_traverser.rb, line 29
def wrapper
  @wrapper ||= Fasterer::Github::ApiWrapper.new(owner, repo)
end