class Gemstory::Reader
Reads the git logs and produce and Hash
Attributes
commit[R]
date[R]
history[R]
line[R]
logs[R]
max_gem_name_size[R]
requested_gems[R]
Public Class Methods
new(gems = [])
click to toggle source
# File lib/gemstory/reader.rb, line 11 def initialize(gems = []) @requested_gems = gems @max_gem_name_size = 0 puts 'Reading Gemfile.lock history' @logs = `git log --reverse --follow -p -- Gemfile.lock` @history = {} end
Public Instance Methods
add_line()
click to toggle source
# File lib/gemstory/reader.rb, line 21 def add_line ruby_gem = line.slice(1, 1000) tab_length = ruby_gem[/\A */].size return unless tab_length == 4 ruby_gem.strip! gem_name_part = ruby_gem.match(/(.*)(?= \()/) if gem_name_part gem_name = gem_name_part[0].to_sym version = ruby_gem.match(/(?<=\()(.*?)(?=\))/)[0] else gem_name = ruby_gem.to_sym version = nil end unless @requested_gems.empty? return unless @requested_gems.include? gem_name.to_s end @max_gem_name_size = gem_name.length if gem_name.length > @max_gem_name_size @history[gem_name] ||= [] @history[gem_name] << { date: date, commit: commit, version: version, author: author } end
call()
click to toggle source
# File lib/gemstory/reader.rb, line 89 def call puts 'Processing history' puts '' @logs.each_line do |line| @line = line.strip next if commit? next if date? next if author? add_line if new_line? && gem? end @history.each do |gem_name, commits| sorted_commits = commits.sort_by { |commit| commit[:date] } @history[gem_name] = sorted_commits.each_with_index.map do |commit, index| if index.zero? commit else commit unless commit[:version] == sorted_commits[index - 1][:version] end end.compact end end
commit?()
click to toggle source
# File lib/gemstory/reader.rb, line 78 def commit? matches = line.match(/(?<=^commit )(.*)/) if matches @commit = matches[0] true else false end end
date?()
click to toggle source
# File lib/gemstory/reader.rb, line 67 def date? matches = line.match(/(?<=^Date: )(.*)/) if matches @date = Date.parse(matches[0]) true else false end end
gem?()
click to toggle source
# File lib/gemstory/reader.rb, line 48 def gem? line.match(/(.*)(\()(.*?)(\))/) end
new_line?()
click to toggle source
# File lib/gemstory/reader.rb, line 52 def new_line? line.match(/^\+ /) end