Class: GitStatistics::Collector
- Inherits:
-
Object
- Object
- GitStatistics::Collector
- Defined in:
- lib/git_statistics/collector.rb
Instance Attribute Summary collapse
-
#commits ⇒ Object
Returns the value of attribute commits.
-
#commits_path ⇒ Object
Returns the value of attribute commits_path.
-
#repo ⇒ Object
Returns the value of attribute repo.
Instance Method Summary collapse
- #acquire_commit_meta(commit_summary) ⇒ Object
- #collect(options = {}) ⇒ Object
- #extract_commit(commit, count) ⇒ Object
-
#initialize(repo, limit, fresh, pretty) ⇒ Collector
constructor
A new instance of Collector.
- #valid_commit?(commit, options) ⇒ Boolean
Constructor Details
#initialize(repo, limit, fresh, pretty) ⇒ Collector
Returns a new instance of Collector.
5 6 7 8 9 |
# File 'lib/git_statistics/collector.rb', line 5 def initialize(repo, limit, fresh, pretty) @repo = repo @commits_path = repo.workdir + '.git_statistics' @commits = Commits.new(@commits_path, fresh, limit, pretty) end |
Instance Attribute Details
#commits ⇒ Object
Returns the value of attribute commits.
3 4 5 |
# File 'lib/git_statistics/collector.rb', line 3 def commits @commits end |
#commits_path ⇒ Object
Returns the value of attribute commits_path.
3 4 5 |
# File 'lib/git_statistics/collector.rb', line 3 def commits_path @commits_path end |
#repo ⇒ Object
Returns the value of attribute repo.
3 4 5 |
# File 'lib/git_statistics/collector.rb', line 3 def repo @repo end |
Instance Method Details
#acquire_commit_meta(commit_summary) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/git_statistics/collector.rb', line 39 def (commit_summary) # Initialize commit data data = (@commits[commit_summary.oid] ||= Hash.new(0)) data[:author] = commit_summary.[:name] data[:author_email] = commit_summary.[:email] data[:time] = commit_summary.[:time].to_s data[:merge] = commit_summary.merge? data[:additions] = commit_summary.additions data[:deletions] = commit_summary.deletions data[:net] = commit_summary.net data[:added_files] = commit_summary.added_files data[:deleted_files] = commit_summary.deleted_files data[:modified_files] = commit_summary.modified_files data[:files] = commit_summary.file_stats.map(&:to_json) data end |
#collect(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/git_statistics/collector.rb', line 11 def collect( = {}) branch_name = [:branch] ? [:branch] : CLI::DEFAULT_BRANCH walker = Rugged::Walker.new(repo) walker.push(repo.branches[branch_name].target) walker.each_with_index do |commit, count| next unless valid_commit?(commit, ) extract_commit(commit, count + 1) @commits.flush_commits end @commits.flush_commits(true) end |
#extract_commit(commit, count) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/git_statistics/collector.rb', line 58 def extract_commit(commit, count) Log.info "Extracting(#{count}) #{commit.oid}" commit_summary = CommitSummary.new(@repo, commit) # Acquire meta information about commit commit_data = (commit_summary) commit_data end |
#valid_commit?(commit, options) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git_statistics/collector.rb', line 27 def valid_commit?(commit, ) unless [:time_since].nil? return false unless commit.[:time] > DateTime.parse([:time_since].to_s).to_time end unless [:time_until].nil? return false unless commit.[:time] < DateTime.parse([:time_until].to_s).to_time end true end |