Skip to content

Commit

Permalink
Merge pull request #61 from olleolleolle/feature/more-docs
Browse files Browse the repository at this point in the history
Avoid deprecated methods, use Ruby's NotImplementedError, fix README issue
  • Loading branch information
danmayer committed Nov 13, 2016
2 parents 563761e + 1dbe6f0 commit 17966be
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Classes:
+-------------------------------+-----------------+
Methods:
+-------------------------------+----------------- +-------------------------------+
+-------------------------------+-----------------+-------------------------------+
| file | klass | method |
+-------------------------------+-----------------+-------------------------------+
| lib/churn/churn_calculator.rb | ChurnCalculator | ChurnCalculator#filters |
Expand Down
23 changes: 12 additions & 11 deletions bin/churn
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,25 @@ Main do
end

def report_churn(output_string)
options = {:minimum_churn_count => params['minimum_churn_count'].value,
:ignore_files => params['ignore_files'].value,
:start_date => params['start_date'].value,
:data_directory => params['data_directory'].value,
:history => params['past_history'].value,
:report => params['report'].value,
:name => params['name'].value
options = {
minimum_churn_count: params['minimum_churn_count'].value,
ignore_files: params['ignore_files'].value,
start_date: params['start_date'].value,
data_directory: params['data_directory'].value,
history: params['past_history'].value,
report: params['report'].value,
name: params['name'].value
}
result = Churn::ChurnCalculator.new(options).report(output_string)
unless output_string
result = YAML::dump(result)
if output_string
result
else
YAML::dump(result)
end
result
end

def run
report = report_churn(!params['yaml'].value)
puts report
end

end
2 changes: 1 addition & 1 deletion lib/churn/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_changes(change)
classes = classes.map{ |klass| {'file' => file, 'klass' => klass} }
methods = methods.map{ |method| {'file' => file, 'klass' => get_klass_for(method), 'method' => method} }
[classes, methods]
rescue => error
rescue
[[],[]]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/churn/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.store_revision_history(revision, hash_data, data_directory)
def self.load_revision_data(revision, data_directory)
#load revision data from scratch folder if it exists
filename = "#{data_directory}/#{revision}.json"
if File.exists?(filename)
if File.exist?(filename)
begin
json_data = File.read(filename)
data = JSON.parse(json_data)
Expand Down
2 changes: 1 addition & 1 deletion lib/churn/scm/bzr_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_revisions

# @raise RunTimeError Currently, the generate history option does not support Bazaar
def generate_history(starting_point)
raise "currently the generate history option does not support bazaar"
raise NotImplementedError, "currently the generate history option does not support bazaar"
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/churn/scm/hg_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_revisions

# @raise RunTimeError Currently, the generate history option does not support Mercurial
def generate_history(starting_point)
raise "currently the generate history option does not support mercurial"
raise NotImplementedError, "currently the generate history option does not support mercurial"
end

private
Expand Down
10 changes: 5 additions & 5 deletions lib/churn/scm/source_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ def self.set_source_control(start_date)
end
end

# @api public
def self.supported?
raise "child class must implement"
raise NotImplementedError, "child class must implement"
end

def initialize(start_date=nil)
@start_date = start_date
end

def get_logs
raise "child class must implement"
raise NotImplementedError, "child class must implement"
end

def get_revisions
raise "child class must implement"
raise NotImplementedError, "child class must implement"
end

def generate_history(starting_point)
raise "child class must implement"
raise NotImplementedError, "child class must implement"
end

def get_updated_files_change_info(revision, revisions)
Expand All @@ -49,7 +50,6 @@ def get_updated_files_change_info(revision, revisions)
updated[recent_file] << removed_range
updated[recent_file] << added_range
else
puts /^---/ =~ line
raise "diff lines that don't match the two patterns aren't expected: '#{line}'"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/churn/scm/svn_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_logs

# @raise RunTimeError Currently, the generate history option does not support Subversion
def generate_history(starting_point)
raise "currently the generate history option does not support subversion"
raise NotImplementedError, "currently the generate history option does not support subversion"
end

# This method is not supported by SVN
Expand Down
2 changes: 1 addition & 1 deletion test/unit/bzr_analyzer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BzrAnalyzerTest < Minitest::Test

should "return all modified files with their line differences" do
@bzr_analyzer.expects(:get_updated_files_from_log).with("1947", ["1947", "1946"]).returns(["--- a/file1.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ b/file1.rb\tSat Jan 16 14:19:32 2010 -0600", "@@ -1,3 +0,0 @@", "--- a/file2.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,7 +0,0 @@", "--- a/file3.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,5 +0,0 @@"])
assert_equal({"/dev/null" => [1..8, 0..0, 1..6, 0..0], "file3.rb" => [], "file1.rb" => [], "file2.rb" => [], "file1.rb" => [1..4, 0..0]}, @bzr_analyzer.get_updated_files_change_info("1947", ["1947", "1946"]))
assert_equal({"/dev/null" => [1..8, 0..0, 1..6, 0..0], "file3.rb" => [], "file2.rb" => [], "file1.rb" => [1..4, 0..0] }, @bzr_analyzer.get_updated_files_change_info("1947", ["1947", "1946"]))
end

should "raise an error if it encounters a line it cannot parse" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/churn_history_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ChurnHistoryTest < Minitest::Test
should "store results" do
within_construct do |container|
Churn::ChurnHistory.store_revision_history('aaa','data','tmp/churn/')
assert File.exists?('tmp/churn/aaa.json')
assert File.exist?('tmp/churn/aaa.json')
data = File.read('tmp/churn/aaa.json')
assert data =~ /data/
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/git_analyzer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GitAnalyzerTest < Minitest::Test
git_analyzer.stubs(:get_updated_files_from_log).returns(lines)
updated = git_analyzer.get_updated_files_change_info(revision, revisions)
expected_hash = {"lib/churn/churn_calculator.rb"=>[18..18, 19..19]}
assert_equal = updated
assert_equal updated, expected_hash
end

should "run get_logs correctly" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/hg_analyzer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class HgAnalyzerTest < Minitest::Test

should "return all modified files with their line differences" do
@hg_analyzer.expects(:get_updated_files_from_log).with("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"]).returns(["--- a/file1.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ b/file1.rb\tSat Jan 16 14:19:32 2010 -0600", "@@ -1,3 +0,0 @@", "--- a/file2.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,7 +0,0 @@", "--- a/file3.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,5 +0,0 @@"])
assert_equal({"/dev/null" => [1..8, 0..0, 1..6, 0..0], "file3.rb" => [], "file1.rb" => [], "file2.rb" => [], "file1.rb" => [1..4, 0..0]}, @hg_analyzer.get_updated_files_change_info("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"]))
assert_equal({"/dev/null" => [1..8, 0..0, 1..6, 0..0], "file3.rb" => [], "file2.rb" => [], "file1.rb" => [1..4, 0..0]}, @hg_analyzer.get_updated_files_change_info("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"]))
end

should "raise an error if it encounters a line it cannot parse" do
Expand Down
4 changes: 3 additions & 1 deletion test/unit/svn_analyzer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
class SvnAnalyzerTest < Minitest::Test

should "parses logs correctly" do
skip("This feature is currently unsupported on SVN")

svn_analyzer = Churn::SvnAnalyzer.new
revision = 'first'
revisions = ['first']
lines = ["--- a/lib/churn/churn_calculator.rb", "+++ b/lib/churn/churn_calculator.rb", "@@ -18,0 +19 @@ module Churn"]
svn_analyzer.stubs(:get_updated_files_from_log).returns(lines)
updated = svn_analyzer.get_updated_files_change_info(revision, revisions)
expected_hash = {"lib/churn/churn_calculator.rb"=>[18..18, 19..19]}
assert_equal = updated
assert_equal updated, expected_hash
end

should "run get_logs correctly" do
Expand Down

0 comments on commit 17966be

Please sign in to comment.