method_log 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e04ff3b961b6a3955ede7783834922849c7e959
4
- data.tar.gz: 36bd0e165bbba5bb13cdabef4110709d80e42921
3
+ metadata.gz: d5660d61fbe34eb21e9a16dd770b6a3d75626377
4
+ data.tar.gz: 0927d7ead89d3bc2a39d6fe315898ef2568c0f8f
5
5
  SHA512:
6
- metadata.gz: 54e9280555d0f24e5fc215351c81a92889b502604e314caad19f6f6a72e891e10dc029e716fbc2100e76737f7f2998540eb95dbcc99d12ec88874e7e80588c87
7
- data.tar.gz: ebba91b228114666d7b69ab73eb7a4e089b03eb60b4b00503da92a6c4313fce0e7f101ad14ee4d6cbf94d9152c0407c101cd3abfdcf25101a0f9cc7cfd0ee46f
6
+ metadata.gz: 0e6fc68bda02985c28fd73977432feb8b5ab81c57732a4612644b42d5951d188a3df3cdf14c38518d0ce3cc1ebebfac7f2035dea433e724d280c8919ec3a7cb3
7
+ data.tar.gz: 5383fb07797d935f46b71f8685443ac5ac8c44e5e5d630d6c269cd24eec4d5d8308f2b2dffc873c4f891cfa997ed01a37c0e978bd9cc493872c7890ddbf94a67
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  ## Method Log
2
2
 
3
- Trace the history of an individual method in a git repository.
4
-
5
- This is a work-in-progress and nowhere near production-ready.
3
+ Trace the history of an individual method in a git repository (experimental).
6
4
 
7
5
  ### Requirements
8
6
 
@@ -17,7 +15,17 @@ This is a work-in-progress and nowhere near production-ready.
17
15
 
18
16
  ### Run
19
17
 
20
- method_log <method-signature> # e.g. Foo::Bar#baz
18
+ $ method_log <options> <method-signature>
19
+
20
+ # options:
21
+ --patch, -p: Generate patch.
22
+ --ruby-version, -r <s>: Parser Ruby version (18, 19, 20, 21) (default: current)
23
+ --max-count, -n <i>: Limit the number of commits to output.
24
+ --stop-at-latest-introduction-of-method, -s: Stop at lastest introduction of method.
25
+ --help, -h: Show usage.
26
+
27
+ # method-signature
28
+ Uses the Ruby Index format e.g. Foo#bar, Bar::Baz#foo, Baz.foo.
21
29
 
22
30
  ### Todo
23
31
 
@@ -9,6 +9,7 @@ module MethodLog
9
9
  end
10
10
 
11
11
  def history(method_identifier, options = {})
12
+ options = { stop_at_latest_introduction_of_method: true }.merge(options)
12
13
  Enumerator.new do |yielder|
13
14
  last_method_commit = nil
14
15
  @repository.commits(options).each do |commit|
@@ -1,3 +1,3 @@
1
1
  module MethodLog
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/spec/api_spec.rb CHANGED
@@ -49,11 +49,10 @@ module MethodLog
49
49
  }))
50
50
  end
51
51
 
52
- it 'finds method which is defined, then removed, and then defined again' do
52
+ it 'finds significant commits for definition of method' do
53
53
  repository = Repository.new(repository_path)
54
54
  commit_1 = repository.commit(source(path: 'foo.rb', source: %{
55
55
  class Foo
56
- def bar; end
57
56
  end
58
57
  }))
59
58
  commit_2 = repository.commit(source(path: 'foo.rb', source: %{
@@ -70,21 +69,72 @@ module MethodLog
70
69
  def bar; end
71
70
  end
72
71
  }))
72
+ commit_5 = repository.commit(source(path: 'foo.rb', source: %{
73
+ class Foo
74
+ def bar
75
+ # implementation
76
+ end
77
+ end
78
+ }))
73
79
 
74
80
  method_commits, method_diffs = commits_and_diffs_for('Foo#bar')
75
81
 
82
+ expect(method_commits.map(&:sha)).to eq([commit_5.sha, commit_3.sha])
83
+ end
84
+
85
+ it 'continues past lastest introduction of method if required' do
86
+ repository = Repository.new(repository_path)
87
+ commit_1 = repository.commit(source(path: 'foo.rb', source: %{
88
+ class Foo
89
+ def bar; end
90
+ end
91
+ }))
92
+ commit_2 = repository.commit(source(path: 'foo.rb', source: %{
93
+ class Foo
94
+ end
95
+ }))
96
+ commit_3 = repository.commit(source(path: 'foo.rb', source: %{
97
+ class Foo
98
+ def bar; end
99
+ end
100
+ }))
101
+
102
+ method_commits, method_diffs = commits_and_diffs_for('Foo#bar', stop_at_latest_introduction_of_method: false)
103
+
76
104
  expect(method_commits.map(&:sha)).to eq([commit_3.sha, commit_2.sha])
77
- expect(method_diffs.map(&:to_s)).to eq([
78
- "+ def bar; end\n",
79
- "- def bar; end\n"
80
- ])
105
+ end
106
+
107
+ it 'continues past lastest introduction of method if required even if method not defined in latest commit' do
108
+ repository = Repository.new(repository_path)
109
+ commit_1 = repository.commit(source(path: 'foo.rb', source: %{
110
+ class Foo
111
+ def bar; end
112
+ end
113
+ }))
114
+ commit_2 = repository.commit(source(path: 'foo.rb', source: %{
115
+ class Foo
116
+ end
117
+ }))
118
+ commit_3 = repository.commit(source(path: 'foo.rb', source: %{
119
+ class Foo
120
+ def bar; end
121
+ end
122
+ }))
123
+ commit_4 = repository.commit(source(path: 'foo.rb', source: %{
124
+ class Foo
125
+ end
126
+ }))
127
+
128
+ method_commits, method_diffs = commits_and_diffs_for('Foo#bar', stop_at_latest_introduction_of_method: false)
129
+
130
+ expect(method_commits.map(&:sha)).to eq([commit_4.sha, commit_3.sha, commit_2.sha])
81
131
  end
82
132
 
83
133
  private
84
134
 
85
- def commits_and_diffs_for(method_identifier)
135
+ def commits_and_diffs_for(method_identifier, options = {})
86
136
  api = API.new(Repository.new(repository_path))
87
- commits_and_diffs = api.diffs(method_identifier)
137
+ commits_and_diffs = api.diffs(method_identifier, options)
88
138
  method_commits = commits_and_diffs.map(&:first)
89
139
  method_diffs = commits_and_diffs.map(&:last)
90
140
  [method_commits, method_diffs]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead