class ReadingLogExtractor::Processor
Attributes
gh_facade[R]
mutex[R]
reponame[R]
username[R]
Public Class Methods
new(username:, gh_facade:)
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 17 def initialize(username:, gh_facade:) @gh_facade = gh_facade @username = username @reponame = ReadingLogExtractor.config.reponame @mutex = Mutex.new end
Public Instance Methods
content(sha1, sha2)
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 36 def content(sha1, sha2) gh_facade .content_between(username, reponame, sha1, sha2) .files .select {|f| f.filename == 'reading-log.md' } .map(&:patch) .first end
latest_commits(last_sha)
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 30 def latest_commits(last_sha) mutex.synchronize do fetch_commits(gh_facade.commits(username, reponame), last_sha) end end
repo_exist?()
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 24 def repo_exist? mutex.synchronize do find_repo(gh_facade.repo_list(username)) end end
Private Instance Methods
fetch_commits(commits, sha, collection = [])
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 66 def fetch_commits(commits, sha, collection = []) limit_reached = false commits .map { |g| init_commit(g) } .each do |commit| unless limit_reached case commit.sha when sha limit_reached = true else collection << commit end end end if !limit_reached && !(next_page = commits.next_page).nil? fetch_commits(next_page, sha, collection) end collection end
find_repo(list)
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 48 def find_repo(list) case list when ->(ary) { ary.empty? } false when ->(ary) { list_has_reponame?(list) } repo = list.lazy.select { |e| e.name == reponame }.first repo.fork # true if it's a forked project # in future gem will ensure weather the for is for # of had-read/reading-log else find_repo(list.next_page) end end
init_commit(gh_commit)
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 89 def init_commit(gh_commit) Commit.new(sha: gh_commit.sha, message: gh_commit.commit.message, author: gh_commit.author.login, avatar: gh_commit.author.avatar_url, date: gh_commit.commit.author.date ) end
list_has_reponame?(list)
click to toggle source
# File lib/reading_log_extractor/processor.rb, line 62 def list_has_reponame?(list) list.map(&:name).include?(reponame) end