meta_commit 0.1.0.alpha → 0.2.0.pre.alpha

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/CONTRIBUTING.md +61 -0
  4. data/README.md +36 -5
  5. data/Rakefile +7 -1
  6. data/config/default.yml +11 -0
  7. data/exe/meta_commit +5 -1
  8. data/lib/meta_commit/changelog/adapters/changelog.rb +94 -0
  9. data/lib/meta_commit/changelog/commands/commit_diff_examiner.rb +50 -0
  10. data/lib/meta_commit/changelog/formatters/keep_a_changelog_ver_report_builder.rb +123 -0
  11. data/lib/meta_commit/cli.rb +71 -17
  12. data/lib/meta_commit/configuration.rb +45 -0
  13. data/lib/meta_commit/configuration_store.rb +27 -0
  14. data/lib/meta_commit/container.rb +80 -0
  15. data/lib/meta_commit/errors.rb +12 -0
  16. data/lib/meta_commit/factories/contextual_ast_node_factory.rb +61 -0
  17. data/lib/meta_commit/factories/diff_factory.rb +37 -0
  18. data/lib/meta_commit/factories/parser_factory.rb +30 -0
  19. data/lib/meta_commit/git/repo.rb +124 -2
  20. data/lib/meta_commit/index/adapters/git_notes.rb +34 -0
  21. data/lib/meta_commit/index/commands/diff_examiner.rb +58 -0
  22. data/lib/meta_commit/message/commands/diff_index_examiner.rb +48 -0
  23. data/lib/meta_commit/message/formatters/commit_message_builder.rb +16 -0
  24. data/lib/meta_commit/models/changes/commit.rb +24 -0
  25. data/lib/meta_commit/models/changes/repository.rb +12 -0
  26. data/lib/meta_commit/models/contextual_ast_node.rb +9 -0
  27. data/lib/meta_commit/models/diffs/diff.rb +31 -3
  28. data/lib/meta_commit/services/change_saver.rb +3 -26
  29. data/lib/meta_commit/services/parse.rb +21 -0
  30. data/lib/meta_commit/version.rb +1 -1
  31. data/lib/meta_commit.rb +34 -27
  32. data/meta_commit.gemspec +5 -0
  33. metadata +90 -23
  34. data/lib/meta_commit/adapters/dump.rb +0 -31
  35. data/lib/meta_commit/adapters/git_notes.rb +0 -28
  36. data/lib/meta_commit/models/ast_path.rb +0 -111
  37. data/lib/meta_commit/models/changes/file.rb +0 -27
  38. data/lib/meta_commit/models/diffs/addition.rb +0 -34
  39. data/lib/meta_commit/models/diffs/changes_in_method.rb +0 -14
  40. data/lib/meta_commit/models/diffs/class_creation.rb +0 -20
  41. data/lib/meta_commit/models/diffs/class_deletion.rb +0 -16
  42. data/lib/meta_commit/models/diffs/class_rename.rb +0 -11
  43. data/lib/meta_commit/models/diffs/deletion.rb +0 -37
  44. data/lib/meta_commit/models/diffs/method_creation.rb +0 -22
  45. data/lib/meta_commit/models/diffs/method_deletion.rb +0 -22
  46. data/lib/meta_commit/models/diffs/module_creation.rb +0 -14
  47. data/lib/meta_commit/models/diffs/module_deletion.rb +0 -14
  48. data/lib/meta_commit/models/diffs/module_rename.rb +0 -11
  49. data/lib/meta_commit/models/diffs/replacement.rb +0 -19
  50. data/lib/meta_commit/models/factories/ast_path_factory.rb +0 -40
  51. data/lib/meta_commit/models/factories/diff_factory.rb +0 -39
  52. data/lib/meta_commit/services/commit_message_builder.rb +0 -23
  53. data/lib/meta_commit/services/diff_examiner.rb +0 -121
  54. data/lib/meta_commit/services/diff_index_examiner.rb +0 -112
@@ -1,4 +1,14 @@
1
1
  module MetaCommit::Models::Diffs
2
+ # Base class for diffs
3
+ # @attr [Symbol] diff_type
4
+ # @attr [String] commit_old
5
+ # @attr [String] commit_new
6
+ # @attr [String] old_file
7
+ # @attr [String] new_file
8
+ # @attr [String] old_lineno
9
+ # @attr [String] new_lineno
10
+ # @attr [MetaCommit::Models::ContextualAstNode] old_ast_path
11
+ # @attr [MetaCommit::Models::ContextualAstNode] new_ast_path
2
12
  class Diff
3
13
 
4
14
  TYPE_ADDITION = :addition
@@ -11,24 +21,42 @@ module MetaCommit::Models::Diffs
11
21
  attr_accessor :old_lineno, :new_lineno
12
22
  attr_accessor :old_ast_path, :new_ast_path
13
23
 
24
+ # @return [String]
14
25
  def inspect
15
26
  string_representation
16
27
  end
17
28
 
29
+ # @return [String]
18
30
  def to_s
19
31
  string_representation
20
32
  end
21
33
 
34
+ # @return [String]
22
35
  def string_representation
23
36
  "#{diff_type} was performed"
24
37
  end
25
38
 
26
- def supports_change_of_type(type)
39
+ # @param [Symbol] type
40
+ # @param [String] old_file_name
41
+ # @param [String] new_file_name
42
+ # @param [String] old_ast_path
43
+ # @param [String] new_ast_path
44
+ # @return [Boolean]
45
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
27
46
  true
28
47
  end
29
48
 
30
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
31
- true
49
+ # @return [Boolean]
50
+ def type_addition?
51
+ @diff_type == TYPE_ADDITION
52
+ end
53
+ # @return [Boolean]
54
+ def type_deletion?
55
+ @diff_type == TYPE_DELETION
56
+ end
57
+ # @return [Boolean]
58
+ def type_replace?
59
+ @diff_type == TYPE_REPLACE
32
60
  end
33
61
  end
34
62
  end
@@ -1,14 +1,10 @@
1
1
  module MetaCommit::Services
2
2
  class ChangeSaver
3
- attr_accessor :repo
3
+ attr_accessor :repo, :meta_adapter
4
4
 
5
- def initialize(repo)
5
+ def initialize(repo, meta_adapter)
6
6
  @repo = repo
7
- end
8
-
9
- def meta_adapter
10
- # @TODO fetch adapter from config
11
- MetaCommit::Adapters::GitNotes.new(@repo.repo.path)
7
+ @meta_adapter = meta_adapter
12
8
  end
13
9
 
14
10
  def store_meta(changes_of_repo)
@@ -18,24 +14,5 @@ module MetaCommit::Services
18
14
  def store_repository_changes(changes_of_repo)
19
15
  meta_adapter.write_repository_change_chunk(repo, changes_of_repo)
20
16
  end
21
-
22
- def store_commit_changes(changes_of_commit)
23
- meta_adapter.write_commit_change_chunk(repo.repo, changes_of_repo, changes_of_commit)
24
- changes_of_commit.each do |changes_of_file|
25
- store_file_changes(changes_of_file)
26
- end
27
- end
28
-
29
- def store_file_changes(changes_of_file)
30
- meta_adapter.write_file_change_chunk(changes_of_file)
31
- uniques_file_changes = changes_of_file.changes.uniq { |diff| diff.to_s }
32
- uniques_file_changes.each do |diff|
33
- store_diff(diff)
34
- end
35
- end
36
-
37
- def store_diff(diff)
38
- meta_adapter.write_diff(diff)
39
- end
40
17
  end
41
18
  end
@@ -0,0 +1,21 @@
1
+ module MetaCommit::Services
2
+ # Parse service responsibility is to parse text if matched parser found and return parsed content
3
+ class Parse
4
+ # @param [MetaCommit::Factories::ParserFactory] factory
5
+ def initialize(factory)
6
+ @factory=factory
7
+ end
8
+
9
+ # Parses content and if matched parser found returns parsed content
10
+ # @param [String] filename
11
+ # @param [String] content
12
+ # @return [MetaCommit::Contracts::Ast, nil]
13
+ def execute(filename, content)
14
+ parser = @factory.create_parser_for(filename, content)
15
+ return nil if parser.nil?
16
+ ast = parser.parse(content)
17
+ ast.parser_class = parser.class
18
+ ast
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module MetaCommit
2
- VERSION = "0.1.0.alpha"
2
+ VERSION = "0.2.0.pre.alpha"
3
3
  end
data/lib/meta_commit.rb CHANGED
@@ -1,35 +1,42 @@
1
- require "meta_commit/version"
1
+ module MetaCommit
2
+ module Extension
3
+ end
2
4
 
3
- require "meta_commit/cli"
4
- require "meta_commit/git/repo"
5
+ require "meta_commit/version"
6
+ require "meta_commit_contracts"
7
+ require "meta_commit/errors"
8
+ require "meta_commit/configuration"
9
+ require "meta_commit/configuration_store"
10
+ require "meta_commit/container"
11
+ require "meta_commit/cli"
5
12
 
6
- require "meta_commit/adapters/dump"
7
- require "meta_commit/adapters/git_notes"
13
+ # changelog command
14
+ require "meta_commit/changelog/adapters/changelog"
15
+ require "meta_commit/changelog/commands/commit_diff_examiner"
16
+ require "meta_commit/changelog/formatters/keep_a_changelog_ver_report_builder"
8
17
 
9
- require "meta_commit/models/ast_path"
10
- require "meta_commit/models/line"
11
- require "meta_commit/models/changes/commit"
12
- require "meta_commit/models/changes/file"
13
- require "meta_commit/models/changes/repository"
18
+ # message command
19
+ require "meta_commit/message/commands/diff_index_examiner"
20
+ require "meta_commit/message/formatters/commit_message_builder"
14
21
 
15
- require "meta_commit/models/diffs/diff"
16
- require "meta_commit/models/diffs/class_creation"
17
- require "meta_commit/models/diffs/class_deletion"
18
- require "meta_commit/models/diffs/class_rename"
19
- require "meta_commit/models/diffs/method_creation"
20
- require "meta_commit/models/diffs/method_deletion"
21
- require "meta_commit/models/diffs/changes_in_method"
22
- require "meta_commit/models/diffs/module_creation"
23
- require "meta_commit/models/diffs/module_deletion"
24
- require "meta_commit/models/diffs/module_rename"
22
+ # index command
23
+ require "meta_commit/index/commands/diff_examiner"
24
+ require "meta_commit/index/adapters/git_notes"
25
25
 
26
- require "meta_commit/models/factories/diff_factory"
27
- require "meta_commit/models/factories/ast_path_factory"
26
+ # models
27
+ require "meta_commit/models/contextual_ast_node"
28
+ require "meta_commit/models/line"
29
+ require "meta_commit/models/changes/commit"
30
+ require "meta_commit/models/changes/repository"
31
+ require "meta_commit/models/diffs/diff"
28
32
 
29
- require "meta_commit/services/diff_examiner"
30
- require "meta_commit/services/diff_index_examiner"
31
- require "meta_commit/services/change_saver"
32
- require "meta_commit/services/commit_message_builder"
33
+ # factories
34
+ require "meta_commit/factories/diff_factory"
35
+ require "meta_commit/factories/contextual_ast_node_factory"
36
+ require "meta_commit/factories/parser_factory"
33
37
 
34
- module MetaCommit
38
+ # services
39
+ require "meta_commit/services/change_saver"
40
+ require "meta_commit/services/parse"
41
+ require "meta_commit/git/repo"
35
42
  end
data/meta_commit.gemspec CHANGED
@@ -18,13 +18,18 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "meta_commit_contracts", "~> 0.1.0"
21
22
  spec.add_runtime_dependency "rugged", "~> 0.25"
23
+ spec.add_runtime_dependency "dry-container", "~> 0.6.0"
22
24
  spec.add_runtime_dependency "parser", "~> 2.4"
23
25
  spec.add_runtime_dependency "thor", "~> 0.19"
24
26
 
25
27
  spec.add_development_dependency "bundler", "~> 1.10"
26
28
  spec.add_development_dependency "rake", "~> 10.0"
27
29
  spec.add_development_dependency "rspec", "~> 3.6"
30
+ spec.add_development_dependency "cucumber", "~> 2.4.0"
31
+ spec.add_development_dependency "aruba", "~> 0.14.2"
28
32
  spec.add_development_dependency "rspec-mocks", "~> 3.6"
29
33
  spec.add_development_dependency "byebug", "~> 9.0"
34
+ spec.add_development_dependency "coveralls", "~> 0.8"
30
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha
4
+ version: 0.2.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav Dobrovolskiy
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-06-18 00:00:00.000000000 Z
12
+ date: 2017-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: meta_commit_contracts
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.0
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: rugged
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -25,6 +39,20 @@ dependencies:
25
39
  - - "~>"
26
40
  - !ruby/object:Gem::Version
27
41
  version: '0.25'
42
+ - !ruby/object:Gem::Dependency
43
+ name: dry-container
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.6.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.6.0
28
56
  - !ruby/object:Gem::Dependency
29
57
  name: parser
30
58
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +123,34 @@ dependencies:
95
123
  - - "~>"
96
124
  - !ruby/object:Gem::Version
97
125
  version: '3.6'
126
+ - !ruby/object:Gem::Dependency
127
+ name: cucumber
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 2.4.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 2.4.0
140
+ - !ruby/object:Gem::Dependency
141
+ name: aruba
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: 0.14.2
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: 0.14.2
98
154
  - !ruby/object:Gem::Dependency
99
155
  name: rspec-mocks
100
156
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +179,20 @@ dependencies:
123
179
  - - "~>"
124
180
  - !ruby/object:Gem::Version
125
181
  version: '9.0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: coveralls
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.8'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '0.8'
126
196
  description:
127
197
  email:
128
198
  - uusername@protonmail.ch
@@ -135,42 +205,39 @@ files:
135
205
  - ".gitignore"
136
206
  - ".travis.yml"
137
207
  - CODE_OF_CONDUCT.md
208
+ - CONTRIBUTING.md
138
209
  - Gemfile
139
210
  - LICENSE.txt
140
211
  - README.md
141
212
  - Rakefile
142
213
  - bin/console
143
214
  - bin/setup
215
+ - config/default.yml
144
216
  - exe/meta_commit
145
217
  - lib/meta_commit.rb
146
- - lib/meta_commit/adapters/dump.rb
147
- - lib/meta_commit/adapters/git_notes.rb
218
+ - lib/meta_commit/changelog/adapters/changelog.rb
219
+ - lib/meta_commit/changelog/commands/commit_diff_examiner.rb
220
+ - lib/meta_commit/changelog/formatters/keep_a_changelog_ver_report_builder.rb
148
221
  - lib/meta_commit/cli.rb
222
+ - lib/meta_commit/configuration.rb
223
+ - lib/meta_commit/configuration_store.rb
224
+ - lib/meta_commit/container.rb
225
+ - lib/meta_commit/errors.rb
226
+ - lib/meta_commit/factories/contextual_ast_node_factory.rb
227
+ - lib/meta_commit/factories/diff_factory.rb
228
+ - lib/meta_commit/factories/parser_factory.rb
149
229
  - lib/meta_commit/git/repo.rb
150
- - lib/meta_commit/models/ast_path.rb
230
+ - lib/meta_commit/index/adapters/git_notes.rb
231
+ - lib/meta_commit/index/commands/diff_examiner.rb
232
+ - lib/meta_commit/message/commands/diff_index_examiner.rb
233
+ - lib/meta_commit/message/formatters/commit_message_builder.rb
151
234
  - lib/meta_commit/models/changes/commit.rb
152
- - lib/meta_commit/models/changes/file.rb
153
235
  - lib/meta_commit/models/changes/repository.rb
154
- - lib/meta_commit/models/diffs/addition.rb
155
- - lib/meta_commit/models/diffs/changes_in_method.rb
156
- - lib/meta_commit/models/diffs/class_creation.rb
157
- - lib/meta_commit/models/diffs/class_deletion.rb
158
- - lib/meta_commit/models/diffs/class_rename.rb
159
- - lib/meta_commit/models/diffs/deletion.rb
236
+ - lib/meta_commit/models/contextual_ast_node.rb
160
237
  - lib/meta_commit/models/diffs/diff.rb
161
- - lib/meta_commit/models/diffs/method_creation.rb
162
- - lib/meta_commit/models/diffs/method_deletion.rb
163
- - lib/meta_commit/models/diffs/module_creation.rb
164
- - lib/meta_commit/models/diffs/module_deletion.rb
165
- - lib/meta_commit/models/diffs/module_rename.rb
166
- - lib/meta_commit/models/diffs/replacement.rb
167
- - lib/meta_commit/models/factories/ast_path_factory.rb
168
- - lib/meta_commit/models/factories/diff_factory.rb
169
238
  - lib/meta_commit/models/line.rb
170
239
  - lib/meta_commit/services/change_saver.rb
171
- - lib/meta_commit/services/commit_message_builder.rb
172
- - lib/meta_commit/services/diff_examiner.rb
173
- - lib/meta_commit/services/diff_index_examiner.rb
240
+ - lib/meta_commit/services/parse.rb
174
241
  - lib/meta_commit/version.rb
175
242
  - meta_commit.gemspec
176
243
  homepage: https://github.com/usernam3/meta_commit
@@ -1,31 +0,0 @@
1
- module MetaCommit::Adapters
2
- class Dump
3
- attr_accessor :repository, :commit, :file
4
-
5
- def initialize
6
-
7
- end
8
-
9
- def write_repository_change_chunk(repository_change)
10
- puts '---'
11
- puts "repo id: #{repository_change.repo_id}"
12
- puts '---'
13
- end
14
-
15
- def write_commit_change_chunk(commit_change)
16
- puts "> commit : #{commit_change.commit_id}"
17
- end
18
-
19
- def write_file_change_chunk(file_change)
20
- puts "file : #{file_change.file_path}"
21
- end
22
-
23
- def write_diff(diff)
24
- puts " - #{diff}"
25
- end
26
-
27
- def write_lines
28
-
29
- end
30
- end
31
- end
@@ -1,28 +0,0 @@
1
- module MetaCommit::Adapters
2
- class GitNotes
3
- attr_accessor :repository, :commit, :file
4
-
5
- def initialize(repository)
6
- @repository = repository
7
- end
8
-
9
- def write_repository_change_chunk(repository, repository_changes)
10
- repository_changes.each do |commit_changes|
11
- diffs=[]
12
- commit_changes.each do |file_changes|
13
- uniques_file_changes = file_changes.changes.uniq { |diff| diff.to_s }
14
- uniques_file_changes.each do |diff|
15
- diffs.push(" - #{diff.string_representation}")
16
- end
17
- end
18
- write_to_notes(repository.path, commit_changes.new_commit_id, diffs.join("\n"))
19
- end
20
- end
21
-
22
- def write_to_notes(repo_path, commit_id, message)
23
- # @TODO escape command
24
- # @TODO add --ref=meta_commit
25
- system("git --git-dir '#{repo_path}' notes add -f -m '#{message}' #{commit_id}")
26
- end
27
- end
28
- end
@@ -1,111 +0,0 @@
1
- module MetaCommit::Models
2
- class AstPath
3
- attr_accessor :ast, :path
4
-
5
- # region helpers
6
- def is_module_definition?(node)
7
- node.type == :module
8
- end
9
-
10
- def is_class_definition?(node)
11
- node.type == :class
12
- end
13
-
14
- def is_method_definition?(node)
15
- node.type == :def
16
- end
17
-
18
- def extract_module_name(node)
19
- node.children.first.children.last.to_s
20
- end
21
-
22
- def extract_class_name(node)
23
- node.children.first.children.last.to_s
24
- end
25
-
26
- def extract_method_name(node)
27
- node.children.first.to_s
28
- end
29
-
30
- def empty_ast?
31
- @ast.nil?
32
- end
33
-
34
- # endregion
35
-
36
- # region external helpers
37
- def is_module?
38
- @ast.type == :module
39
- end
40
-
41
- def is_class?
42
- @ast.type == :class
43
- end
44
-
45
- def is_method?
46
- @ast.type == :def
47
- end
48
-
49
- # on created class only first line goes to diff
50
- def is_name_of_class?
51
- (@ast.type == :const) and (@path.length > 1) and (@path[@path.length - 1 - 1].type == :class)
52
- end
53
-
54
- # on created module only first line goes to diff
55
- def is_name_of_module?
56
- (@ast.type == :const) and (@path.length > 1) and (@path[@path.length - 1 - 1].type == :module)
57
- end
58
-
59
- def module_name
60
- @ast.children.first.children.last.to_s
61
- end
62
-
63
- def class_name
64
- @ast.children.first.children.last.to_s
65
- end
66
-
67
- def method_name
68
- @ast.children.first.to_s
69
- end
70
-
71
- def name_of_context_module
72
- @path.reverse.each do |parent|
73
- return extract_module_name(parent) if is_module_definition?(parent)
74
- end
75
- end
76
-
77
- def name_of_context_class
78
- @path.reverse.each do |parent|
79
- return extract_class_name(parent) if is_class_definition?(parent)
80
- end
81
- end
82
-
83
- def name_of_context_method
84
- @path.reverse.each do |parent|
85
- return extract_method_name(parent) if is_method_definition?(parent)
86
- end
87
- end
88
-
89
- def is_in_context_of_module?
90
- @path.each do |parent|
91
- return true if is_module_definition?(parent)
92
- end
93
- false
94
- end
95
-
96
- def is_in_context_of_class?
97
- @path.each do |parent|
98
- return true if is_class_definition?(parent)
99
- end
100
- false
101
- end
102
-
103
- def is_in_context_of_method?
104
- @path.each do |parent|
105
- return true if is_method_definition?(parent)
106
- end
107
- false
108
- end
109
- # endregion
110
- end
111
- end
@@ -1,27 +0,0 @@
1
- module MetaCommit::Models::Changes
2
- class File
3
- attr_accessor :old_file_path, :new_file_path, :changes
4
-
5
- def initialize(old_file_path, new_file_path)
6
- @old_file_path = old_file_path
7
- @new_file_path = new_file_path
8
- @changes = []
9
- end
10
-
11
- def push(change)
12
- @changes.push(change)
13
- end
14
-
15
- def file_path
16
- if @new_file_path == @new_file_path
17
- @new_file_path
18
- else
19
- "#{@old_file_path} -> #{@new_file_path}"
20
- end
21
- end
22
-
23
- def each(&block)
24
- @changes.each(&block)
25
- end
26
- end
27
- end
@@ -1,34 +0,0 @@
1
- module MetaCommit::Models::Diffs
2
- class Addition < Diff
3
- def string_representation
4
- action = 'created'
5
- if @new_ast_path.is_class?
6
- if @new_ast_path.is_in_context_of_module?
7
- return "#{action} #{new_ast_path.name_of_context_module}::#{new_ast_path.class_name}"
8
- end
9
- return "#{action} class #{new_ast_path.class_name}"
10
- end
11
- if @new_ast_path.is_name_of_class?
12
- if @new_ast_path.is_in_context_of_module?
13
- return "#{action} #{new_ast_path.name_of_context_module}::#{new_ast_path.name_of_context_class}"
14
- end
15
- return "#{action} class #{new_ast_path.name_of_context_class}"
16
- end
17
- if @new_ast_path.is_method?
18
- if @new_ast_path.is_in_context_of_class?
19
- return "#{action} #{new_ast_path.name_of_context_class}##{new_ast_path.method_name}"
20
- end
21
- if @new_ast_path.is_in_context_of_module?
22
- if @new_ast_path.is_in_context_of_class?
23
- return "#{action} #{new_ast_path.name_of_context_module}::#{new_ast_path.name_of_context_class}##{new_ast_path.method_name}"
24
- end
25
- return "#{action} #{new_ast_path.name_of_context_module}##{new_ast_path.method_name}"
26
- end
27
- end
28
- if @new_ast_path.is_in_context_of_method?
29
- return "changes in method #{@new_ast_path.name_of_context_method}"
30
- end
31
- 'addition was performed'
32
- end
33
- end
34
- end
@@ -1,14 +0,0 @@
1
- module MetaCommit::Models::Diffs
2
- class ChangesInMethod < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Models::Diffs::Diff::TYPE_REPLACE && !old_ast_path.empty_ast? && !new_ast_path.empty_ast? && old_ast_path.is_in_context_of_method? && new_ast_path.is_in_context_of_method?
5
- end
6
-
7
- def string_representation
8
- if @new_ast_path.is_in_context_of_class?
9
- return "changes in #{new_ast_path.name_of_context_class}##{new_ast_path.name_of_context_method}"
10
- end
11
- "changes in ##{new_ast_path.name_of_context_method}"
12
- end
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- module MetaCommit::Models::Diffs
2
- class ClassCreation < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Models::Diffs::Diff::TYPE_ADDITION && !new_ast_path.empty_ast? && (new_ast_path.is_class? || new_ast_path.is_name_of_class?)
5
- end
6
-
7
- def string_representation
8
- if @new_ast_path.is_class?
9
- if @new_ast_path.is_in_context_of_module?
10
- return "created #{new_ast_path.name_of_context_module}::#{new_ast_path.class_name}"
11
- end
12
- return "created class #{new_ast_path.class_name}"
13
- end
14
- if @new_ast_path.is_in_context_of_module?
15
- return "created #{new_ast_path.name_of_context_module}::#{new_ast_path.name_of_context_class}"
16
- end
17
- "created class #{new_ast_path.name_of_context_class}"
18
- end
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- module MetaCommit::Models::Diffs
2
- class ClassDeletion < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Models::Diffs::Diff::TYPE_DELETION && !old_ast_path.empty_ast? && (old_ast_path.is_class? || old_ast_path.is_name_of_class?)
5
- end
6
-
7
- def string_representation
8
- if @old_ast_path.is_class?
9
- if @old_ast_path.is_in_context_of_module?
10
- return "removed class #{old_ast_path.class_name} from module #{old_ast_path.name_of_context_module}"
11
- end
12
- end
13
- "removed class #{old_ast_path.name_of_context_class}"
14
- end
15
- end
16
- end