Class: GitSme::CommitAnalyzer
- Inherits:
-
Object
- Object
- GitSme::CommitAnalyzer
- Defined in:
- lib/git_sme/commit_analyzer.rb
Instance Attribute Summary collapse
-
#analysis ⇒ Object
readonly
Returns the value of attribute analysis.
-
#analyzed ⇒ Object
(also: #analyzed?)
readonly
Returns the value of attribute analyzed.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#valid ⇒ Object
(also: #valid?)
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
- #analyze(force: false) ⇒ Object
-
#initialize(commit_loader, enable_cache: true) ⇒ CommitAnalyzer
constructor
A new instance of CommitAnalyzer.
Constructor Details
#initialize(commit_loader, enable_cache: true) ⇒ CommitAnalyzer
Returns a new instance of CommitAnalyzer.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/git_sme/commit_analyzer.rb', line 8 def initialize(commit_loader, enable_cache: true) @enable_cache = true @commit_loader = commit_loader @analyzed = false @valid = @commit_loader.valid? @error_message = @commit_loader. @analysis = {} @cache = GitSme::Cache.new(@commit_loader.repo.path.gsub('/.git/', ''), enabled: @enable_cache, file_suffix: "#{@commit_loader.branch}-analysis" ) end |
Instance Attribute Details
#analysis ⇒ Object (readonly)
Returns the value of attribute analysis.
3 4 5 |
# File 'lib/git_sme/commit_analyzer.rb', line 3 def analysis @analysis end |
#analyzed ⇒ Object (readonly) Also known as: analyzed?
Returns the value of attribute analyzed.
3 4 5 |
# File 'lib/git_sme/commit_analyzer.rb', line 3 def analyzed @analyzed end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
3 4 5 |
# File 'lib/git_sme/commit_analyzer.rb', line 3 def @error_message end |
#valid ⇒ Object (readonly) Also known as: valid?
Returns the value of attribute valid.
3 4 5 |
# File 'lib/git_sme/commit_analyzer.rb', line 3 def valid @valid end |
Instance Method Details
#analyze(force: false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/git_sme/commit_analyzer.rb', line 21 def analyze(force: false) return unless valid? return if analyzed? && !force @commit_loader.load @analysis = @cache.load new_analysis = [] if !@commit_loader.new_commits? || !@analysis.any? if block_given? @analysis = analyze_new_commits(@commit_loader.commits) do |commit_count, total_commits| yield(commit_count, total_commits) end else @analysis = analyze_new_commits(@commit_loader.commits) end elsif @commit_loader.new_commits? new_analysis = if block_given? analyze_new_commits(@commit_loader.new_commits) do |commit_count, total_commits| yield(commit_count, total_commits) end else analyze_new_commits(@commit_loader.new_commits) end summed_merge(@analysis[:by_user], new_analysis[:by_user]) summed_merge(@analysis[:by_file], new_analysis[:by_file]) end @cache.save(@analysis) @analyzed = true end |