meta_commit_ruby_support 0.1.0 → 0.1.1

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: 92e6f234ecea325e18fb4bad8a850b6f3795bc87
4
- data.tar.gz: bf9067405e0c9ce54551392a2e1ab55d184d3cc2
3
+ metadata.gz: 7767dc4aa3694060d8171d3f3e3dfc3f8c2894e0
4
+ data.tar.gz: 0caf9b1a78f4eb5f3525dbbc37cfd74c487b84ab
5
5
  SHA512:
6
- metadata.gz: b557532f65e31701c468c9b3af93a271bc515a678fdeaee5816c97918fbf02bec8f465c0d7dc695b72698e218c28fe99e551abd69448ccbe0be05284f7d8d293
7
- data.tar.gz: a1ddfefb90359a140b95fca90f1068acb4b3176a19add2cbd3f25816cb449f8c279f6322e3173fb6dd37041e37ddacb2cb48cea2a9b3bf89df5fc97463ffe124
6
+ metadata.gz: c045b634d67c11488f3398b308399d5ec110a474d4e1d53b017ff1afaea11fe1beb319d03fca1b9e6219bc9b16b1dd96bb58c90e80fa27a667c28723665eb8d2
7
+ data.tar.gz: 30b4143b17d08876aaf2cd2d4bd2fbe82f7011d02428c8e65910c10ff20c5f2694bc19bc3f9744538c7fa84c701702923199a5ec731ee6eee365bee7676ad2ad
@@ -8,6 +8,7 @@ module MetaCommit
8
8
  end
9
9
 
10
10
  require "meta_commit_contracts"
11
+ require "meta_commit_ruby_support/helpers/contextual_ast_accessor"
11
12
  # parsers
12
13
  require "meta_commit_ruby_support/parsers/ruby"
13
14
  # diffs
@@ -1,14 +1,16 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ChangesInMethod < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE && !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? && is_in_context_of_method?(old_ast_path) && is_in_context_of_method?(new_ast_path)
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE &&
5
+ contextual_ast_has_target_node(context.old_contextual_ast) && contextual_ast_has_target_node(context.new_contextual_ast) &&
6
+ is_in_context_of_method?(context.old_contextual_ast) && is_in_context_of_method?(context.new_contextual_ast)
5
7
  end
6
8
 
7
9
  def string_representation
8
- if is_in_context_of_class?(@new_ast_path)
9
- return "changes in #{name_of_context_class(new_ast_path)}##{name_of_context_method(new_ast_path)}"
10
+ if is_in_context_of_class?(change_context.new_contextual_ast)
11
+ return "changes in #{name_of_context_class(change_context.new_contextual_ast)}##{name_of_context_method(change_context.new_contextual_ast)}"
10
12
  end
11
- "changes in ##{name_of_context_method(new_ast_path)}"
13
+ "changes in ##{name_of_context_method(change_context.new_contextual_ast)}"
12
14
  end
13
15
  end
14
16
  end
@@ -1,20 +1,22 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ClassCreation < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION && !new_ast_path.target_node.empty_ast? && (new_ast_path.target_node.is_class? || is_name_of_class?(new_ast_path))
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION &&
5
+ contextual_ast_has_target_node(context.new_contextual_ast) &&
6
+ (context.new_contextual_ast.target_node.is_class? || is_name_of_class?(context.new_contextual_ast))
5
7
  end
6
8
 
7
9
  def string_representation
8
- if @new_ast_path.target_node.is_class?
9
- if is_in_context_of_module?(@new_ast_path)
10
- return "created #{name_of_context_module(new_ast_path)}::#{new_ast_path.target_node.class_name}"
10
+ if change_context.new_contextual_ast.target_node.is_class?
11
+ if is_in_context_of_module?(change_context.new_contextual_ast)
12
+ return "create #{name_of_context_module(change_context.new_contextual_ast)}::#{change_context.new_contextual_ast.target_node.class_name}"
11
13
  end
12
- return "created class #{new_ast_path.class_name}"
14
+ return "create class #{change_context.new_contextual_ast.target_node.class_name}"
13
15
  end
14
- if is_in_context_of_module?(@new_ast_path)
15
- return "created #{name_of_context_module(new_ast_path)}::#{name_of_context_class(new_ast_path)}"
16
+ if is_in_context_of_module?(change_context.new_contextual_ast)
17
+ return "create #{name_of_context_module(change_context.new_contextual_ast)}::#{name_of_context_class(change_context.new_contextual_ast)}"
16
18
  end
17
- "created class #{name_of_context_class(new_ast_path)}"
19
+ "create class #{name_of_context_class(change_context.new_contextual_ast)}"
18
20
  end
19
21
  end
20
22
  end
@@ -1,16 +1,19 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ClassDeletion < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION && !old_ast_path.target_node.empty_ast? && (old_ast_path.target_node.is_class? || is_name_of_class?(old_ast_path))
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION &&
5
+ contextual_ast_has_target_node(context.old_contextual_ast) &&
6
+ (context.old_contextual_ast.target_node.is_class? || is_name_of_class?(context.old_contextual_ast))
5
7
  end
6
8
 
7
9
  def string_representation
8
- if @old_ast_path.target_node.is_class?
9
- if is_in_context_of_module?(@old_ast_path)
10
- return "removed class #{old_ast_path.target_node.class_name} from module #{name_of_context_module(old_ast_path)}"
10
+ if change_context.old_contextual_ast.target_node.is_class?
11
+ if is_in_context_of_module?(change_context.old_contextual_ast)
12
+ return "remove class #{change_context.old_contextual_ast.target_node.class_name} from module #{name_of_context_module(change_context.old_contextual_ast)}"
11
13
  end
14
+ return "remove class #{change_context.old_contextual_ast.target_node.class_name}"
12
15
  end
13
- "removed class #{name_of_context_class(old_ast_path)}"
16
+ "remove class #{name_of_context_class(change_context.old_contextual_ast)}"
14
17
  end
15
18
  end
16
19
  end
@@ -1,11 +1,14 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ClassRename < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE && !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? && is_name_of_class?(old_ast_path) && is_name_of_class?(new_ast_path)
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE &&
5
+ contextual_ast_has_target_node(context.old_contextual_ast) &&
6
+ contextual_ast_has_target_node(context.new_contextual_ast) &&
7
+ is_name_of_class?(context.old_contextual_ast) && is_name_of_class?(context.new_contextual_ast)
5
8
  end
6
9
 
7
10
  def string_representation
8
- "renamed class #{name_of_context_class(old_ast_path)} to #{name_of_context_class(new_ast_path)}"
11
+ "rename class #{name_of_context_class(change_context.old_contextual_ast)} to #{name_of_context_class(change_context.new_contextual_ast)}"
9
12
  end
10
13
  end
11
14
  end
@@ -1,40 +1,19 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
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
12
3
  class Diff < MetaCommit::Contracts::Diff
4
+ include MetaCommit::Extension::RubySupport::Helpers::ContextualAstAccessor
13
5
 
14
- TYPE_ADDITION = :addition
15
- TYPE_DELETION = :deletion
16
- TYPE_REPLACE = :replace
17
6
  SUPPORTED_PARSERS = [MetaCommit::Extension::RubySupport::Parsers::Ruby]
18
7
 
19
- attr_accessor :diff_type
20
- attr_accessor :commit_old, :commit_new
21
- attr_accessor :old_file, :new_file
22
- attr_accessor :old_lineno, :new_lineno
23
- attr_accessor :old_ast_path, :new_ast_path
24
-
25
8
  # @param [Class] parser
26
9
  # @return [Boolean]
27
10
  def supports_parser?(parser)
28
11
  SUPPORTED_PARSERS.include?(parser)
29
12
  end
30
13
 
31
- # @param [Symbol] type
32
- # @param [String] old_file_name
33
- # @param [String] new_file_name
34
- # @param [String] old_ast_path
35
- # @param [String] new_ast_path
14
+ # @param [MetaCommit::Contracts::ChangeContext] context
36
15
  # @return [Boolean]
37
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
16
+ def supports_change(context)
38
17
  true
39
18
  end
40
19
 
@@ -50,95 +29,22 @@ module MetaCommit::Extension::RubySupport::Diffs
50
29
 
51
30
  # @return [String]
52
31
  def string_representation
53
- "#{diff_type} was performed"
32
+ "perform #{change_context.type}"
54
33
  end
55
34
 
56
35
  # @return [Boolean]
57
36
  def type_addition?
58
- @diff_type == TYPE_ADDITION
37
+ change_context.type == TYPE_ADDITION
59
38
  end
60
39
 
61
40
  # @return [Boolean]
62
41
  def type_deletion?
63
- @diff_type == TYPE_DELETION
42
+ change_context.type == TYPE_DELETION
64
43
  end
65
44
 
66
45
  # @return [Boolean]
67
46
  def type_replace?
68
- @diff_type == TYPE_REPLACE
69
- end
70
-
71
-
72
- # @param [Object] ast
73
- # @param [Integer] depth
74
- # @return [String]
75
- def path_to_component(ast, depth=nil)
76
- depth = -1 if depth.nil?
77
- result = []
78
- result.concat([name_of_context_module(ast), is_in_context_of_class?(ast) && depth < 1 ? '::' : '']) if is_in_context_of_module?(ast) && depth < 2
79
- result.concat([name_of_context_class(ast)]) if is_in_context_of_class?(ast) && depth < 1
80
- result.concat(['#', name_of_context_method(ast)]) if is_in_context_of_method?(ast) && depth < 0
81
- result.join('')
82
- end
83
-
84
- # on created class only first line goes to diff
85
- # @param [MetaCommit::Model::ContextualAstNode] ast
86
- def is_name_of_class?(ast)
87
- (ast.target_node.ast.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].ast.type == :class)
88
- end
89
-
90
- # on created module only first line goes to diff
91
- # @param [MetaCommit::Model::ContextualAstNode] ast
92
- def is_name_of_module?(ast)
93
- (ast.target_node.ast.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].ast.type == :module)
94
- end
95
-
96
- # @param [MetaCommit::Model::ContextualAstNode] ast
97
- def name_of_context_module(ast)
98
- ast.context_nodes.reverse.each do |parent|
99
- return parent.module_name if parent.is_module?
100
- end
101
- end
102
-
103
- # @param [MetaCommit::Model::ContextualAstNode] ast
104
- def name_of_context_class(ast)
105
- ast.context_nodes.reverse.each do |parent|
106
- return parent.class_name if parent.is_class?
107
- end
108
- end
109
-
110
- # @param [MetaCommit::Model::ContextualAstNode] ast
111
- def name_of_context_method(ast)
112
- ast.context_nodes.reverse.each do |parent|
113
- return parent.method_name if parent.is_method?
114
- end
115
- end
116
-
117
- # @param [MetaCommit::Model::ContextualAstNode] ast
118
- # @return [Boolean]
119
- def is_in_context_of_module?(ast)
120
- ast.context_nodes.each do |parent|
121
- return true if parent.is_module?
122
- end
123
- false
124
- end
125
-
126
- # @param [MetaCommit::Model::ContextualAstNode] ast
127
- # @return [Boolean]
128
- def is_in_context_of_class?(ast)
129
- ast.context_nodes.each do |parent|
130
- return true if parent.is_class?
131
- end
132
- false
133
- end
134
-
135
- # @param [MetaCommit::Model::ContextualAstNode] ast
136
- # @return [Boolean]
137
- def is_in_context_of_method?(ast)
138
- ast.context_nodes.each do |parent|
139
- return true if parent.is_method?
140
- end
141
- false
47
+ change_context.type == TYPE_REPLACE
142
48
  end
143
49
  end
144
50
  end
@@ -1,14 +1,18 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class InitializeChanged < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE &&
5
- !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? &&
6
- is_in_context_of_method?(old_ast_path) && is_in_context_of_method?(new_ast_path) &&
7
- name_of_context_method(old_ast_path) == 'initialize' && name_of_context_method(new_ast_path) == 'initialize'
3
+ INITIALIZE_METHOD_NAME = 'initialize'
4
+
5
+ def supports_change(context)
6
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE &&
7
+ contextual_ast_has_target_node(context.old_contextual_ast) &&
8
+ contextual_ast_has_target_node(context.new_contextual_ast) &&
9
+ is_in_context_of_method?(context.old_contextual_ast) &&
10
+ is_in_context_of_method?(context.new_contextual_ast) &&
11
+ name_of_context_method(context.old_contextual_ast) == INITIALIZE_METHOD_NAME && name_of_context_method(context.new_contextual_ast) == INITIALIZE_METHOD_NAME
8
12
  end
9
13
 
10
14
  def string_representation
11
- "changes in initialization of #{path_to_component(new_ast_path, 0)}"
15
+ "change initialization of #{path_to_component(change_context.new_contextual_ast, 0)}"
12
16
  end
13
17
  end
14
18
  end
@@ -1,22 +1,24 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class MethodCreation < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION && !new_ast_path.target_node.empty_ast? && (new_ast_path.target_node.is_method? || is_in_context_of_method?(new_ast_path))
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION &&
5
+ contextual_ast_has_target_node(context.new_contextual_ast) &&
6
+ (context.new_contextual_ast.target_node.is_method? || is_in_context_of_method?(context.new_contextual_ast))
5
7
  end
6
8
 
7
9
  def string_representation
8
- if @new_ast_path.target_node.is_method?
9
- if is_in_context_of_module?(@new_ast_path)
10
- if is_in_context_of_class?(@new_ast_path)
11
- return "created #{name_of_context_module(new_ast_path)}::#{name_of_context_class(new_ast_path)}##{new_ast_path.target_node.method_name}"
10
+ if change_context.new_contextual_ast.target_node.is_method?
11
+ if is_in_context_of_module?(change_context.new_contextual_ast)
12
+ if is_in_context_of_class?(change_context.new_contextual_ast)
13
+ return "create #{name_of_context_module(change_context.new_contextual_ast)}::#{name_of_context_class(change_context.new_contextual_ast)}##{change_context.new_contextual_ast.target_node.method_name}"
12
14
  end
13
- return "created #{name_of_context_module(new_ast_path)}##{new_ast_path.target_node.method_name}"
15
+ return "create #{name_of_context_module(change_context.new_contextual_ast)}##{change_context.new_contextual_ast.target_node.method_name}"
14
16
  end
15
- if is_in_context_of_class?(@new_ast_path)
16
- return "created #{name_of_context_class(new_ast_path)}##{new_ast_path.target_node.method_name}"
17
+ if is_in_context_of_class?(change_context.new_contextual_ast)
18
+ return "create #{name_of_context_class(change_context.new_contextual_ast)}##{change_context.new_contextual_ast.target_node.method_name}"
17
19
  end
18
20
  end
19
- "changes in method #{name_of_context_method(new_ast_path)}"
21
+ "changes in method #{name_of_context_method(change_context.new_contextual_ast)}"
20
22
  end
21
23
  end
22
24
  end
@@ -1,22 +1,24 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class MethodDeletion < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION && !old_ast_path.target_node.empty_ast? && (old_ast_path.target_node.is_method? || is_in_context_of_method?(old_ast_path))
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION &&
5
+ contextual_ast_has_target_node(context.old_contextual_ast) &&
6
+ (context.old_contextual_ast.target_node.is_method? || is_in_context_of_method?(context.old_contextual_ast))
5
7
  end
6
8
 
7
9
  def string_representation
8
- if @old_ast_path.target_node.is_method?
9
- if is_in_context_of_module?(@old_ast_path)
10
- if is_in_context_of_class?(@old_ast_path)
11
- return "removed #{name_of_context_module(old_ast_path)}::#{name_of_context_class(old_ast_path)}##{old_ast_path.target_node.method_name}"
10
+ if change_context.old_contextual_ast.target_node.is_method?
11
+ if is_in_context_of_module?(change_context.old_contextual_ast)
12
+ if is_in_context_of_class?(change_context.old_contextual_ast)
13
+ return "remove #{name_of_context_module(change_context.old_contextual_ast)}::#{name_of_context_class(change_context.old_contextual_ast)}##{change_context.old_contextual_ast.target_node.method_name}"
12
14
  end
13
- return "removed method #{old_ast_path.target_node.method_name} from module #{name_of_context_module(old_ast_path)}"
15
+ return "remove method #{change_context.old_contextual_ast.target_node.method_name} from module #{name_of_context_module(change_context.old_contextual_ast)}"
14
16
  end
15
- if is_in_context_of_class?(@old_ast_path)
16
- return "removed #{name_of_context_class(old_ast_path)}##{old_ast_path.target_node.method_name}"
17
+ if is_in_context_of_class?(change_context.old_contextual_ast)
18
+ return "remove #{name_of_context_class(change_context.old_contextual_ast)}##{change_context.old_contextual_ast.target_node.method_name}"
17
19
  end
18
20
  end
19
- "changes in method #{name_of_context_method(old_ast_path)}"
21
+ "changes in method #{name_of_context_method(change_context.old_contextual_ast)}"
20
22
  end
21
23
  end
22
24
  end
@@ -1,14 +1,24 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ModuleCreation < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION && !new_ast_path.target_node.empty_ast? && (new_ast_path.target_node.is_module? || is_name_of_module?(new_ast_path))
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION &&
5
+ contextual_ast_has_target_node(context.new_contextual_ast) &&
6
+ (context.new_contextual_ast.target_node.is_module? || is_name_of_module?(context.new_contextual_ast))
5
7
  end
6
8
 
7
9
  def string_representation
8
- if @new_ast_path.target_node.is_module?
9
- return "created module #{new_ast_path.target_node.module_name}"
10
+ if change_context.new_contextual_ast.whole_file_change
11
+ added_module=change_context.new_contextual_ast.target_node
12
+ created_class_names=added_module.classes.map do |class_ast|
13
+ class_ast.class_name
14
+ end
15
+ # @TODO maybe invoke created class change
16
+ return "#{created_class_names.join(',')} added to #{change_context.new_contextual_ast.target_node.module_name}" unless created_class_names.empty?
10
17
  end
11
- "created module #{name_of_context_module(new_ast_path)}"
18
+ if change_context.new_contextual_ast.target_node.is_module?
19
+ return "create module #{change_context.new_contextual_ast.target_node.module_name}"
20
+ end
21
+ "create module #{name_of_context_module(change_context.new_contextual_ast)}"
12
22
  end
13
23
  end
14
24
  end
@@ -1,14 +1,16 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ModuleDeletion < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION && !old_ast_path.target_node.empty_ast? && (old_ast_path.target_node.is_module? || is_name_of_module?(old_ast_path))
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION &&
5
+ contextual_ast_has_target_node(context.old_contextual_ast) &&
6
+ (context.old_contextual_ast.target_node.is_module? || is_name_of_module?(context.old_contextual_ast))
5
7
  end
6
8
 
7
9
  def string_representation
8
- if @old_ast_path.target_node.is_module?
9
- return "removed module #{old_ast_path.target_node.module_name}"
10
+ if change_context.old_contextual_ast.target_node.is_module?
11
+ return "remove module #{change_context.old_contextual_ast.target_node.module_name}"
10
12
  end
11
- "removed module #{name_of_context_module(old_ast_path)}"
13
+ "remove module #{name_of_context_module(change_context.old_contextual_ast)}"
12
14
  end
13
15
  end
14
16
  end
@@ -1,11 +1,15 @@
1
1
  module MetaCommit::Extension::RubySupport::Diffs
2
2
  class ModuleRename < Diff
3
- def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
- type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE && !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? && is_name_of_module?(old_ast_path) && is_name_of_module?(new_ast_path)
3
+ def supports_change(context)
4
+ context.type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE &&
5
+ contextual_ast_has_target_node(context.old_contextual_ast) &&
6
+ contextual_ast_has_target_node(context.new_contextual_ast) &&
7
+ is_name_of_module?(context.old_contextual_ast) &&
8
+ is_name_of_module?(context.new_contextual_ast)
5
9
  end
6
10
 
7
11
  def string_representation
8
- "renamed module #{name_of_context_module(old_ast_path)} to #{name_of_context_module(new_ast_path)}"
12
+ "rename module #{name_of_context_module(change_context.old_contextual_ast)} to #{name_of_context_module(change_context.new_contextual_ast)}"
9
13
  end
10
14
  end
11
15
  end
@@ -0,0 +1,79 @@
1
+ module MetaCommit::Extension::RubySupport::Helpers
2
+ module ContextualAstAccessor
3
+ # @param [Object] ast
4
+ # @param [Integer] depth
5
+ # @return [String]
6
+ def path_to_component(ast, depth=nil)
7
+ depth = -1 if depth.nil?
8
+ result = []
9
+ result.concat([name_of_context_module(ast), is_in_context_of_class?(ast) && depth < 1 ? '::' : '']) if is_in_context_of_module?(ast) && depth < 2
10
+ result.concat([name_of_context_class(ast)]) if is_in_context_of_class?(ast) && depth < 1
11
+ result.concat(['#', name_of_context_method(ast)]) if is_in_context_of_method?(ast) && depth < 0
12
+ result.join('')
13
+ end
14
+
15
+ # on created class only first line goes to diff
16
+ # @param [MetaCommit::Model::ContextualAstNode] ast
17
+ def is_name_of_class?(ast)
18
+ (ast.target_node.ast.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].ast.type == :class)
19
+ end
20
+
21
+ # on created module only first line goes to diff
22
+ # @param [MetaCommit::Model::ContextualAstNode] ast
23
+ def is_name_of_module?(ast)
24
+ (ast.target_node.ast.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].ast.type == :module)
25
+ end
26
+
27
+ # @param [MetaCommit::Model::ContextualAstNode] ast
28
+ def name_of_context_module(ast)
29
+ ast.context_nodes.reverse.each do |parent|
30
+ return parent.module_name if parent.is_module?
31
+ end
32
+ end
33
+
34
+ # @param [MetaCommit::Model::ContextualAstNode] ast
35
+ def name_of_context_class(ast)
36
+ ast.context_nodes.reverse.each do |parent|
37
+ return parent.class_name if parent.is_class?
38
+ end
39
+ end
40
+
41
+ # @param [MetaCommit::Model::ContextualAstNode] ast
42
+ def name_of_context_method(ast)
43
+ ast.context_nodes.reverse.each do |parent|
44
+ return parent.method_name if parent.is_method?
45
+ end
46
+ end
47
+
48
+ # @param [MetaCommit::Model::ContextualAstNode] ast
49
+ # @return [Boolean]
50
+ def is_in_context_of_module?(ast)
51
+ ast.context_nodes.each do |parent|
52
+ return true if parent.is_module?
53
+ end
54
+ false
55
+ end
56
+
57
+ # @param [MetaCommit::Model::ContextualAstNode] ast
58
+ # @return [Boolean]
59
+ def is_in_context_of_class?(ast)
60
+ ast.context_nodes.each do |parent|
61
+ return true if parent.is_class?
62
+ end
63
+ false
64
+ end
65
+
66
+ # @param [MetaCommit::Model::ContextualAstNode] ast
67
+ # @return [Boolean]
68
+ def is_in_context_of_method?(ast)
69
+ ast.context_nodes.each do |parent|
70
+ return true if parent.is_method?
71
+ end
72
+ false
73
+ end
74
+
75
+ def contextual_ast_has_target_node(ast)
76
+ !ast.target_node.nil? && !ast.target_node.empty_ast?
77
+ end
78
+ end
79
+ end
@@ -21,7 +21,6 @@ module MetaCommit::Extension::RubySupport
21
21
  MetaCommit::Extension::RubySupport::Diffs::ModuleCreation,
22
22
  MetaCommit::Extension::RubySupport::Diffs::ModuleDeletion,
23
23
  MetaCommit::Extension::RubySupport::Diffs::ModuleRename,
24
- MetaCommit::Extension::RubySupport::Diffs::Diff,
25
24
  ]
26
25
  end
27
26
  end
@@ -70,5 +70,21 @@ module MetaCommit::Extension::RubySupport::Models
70
70
  @ast.children.first.to_s
71
71
  end
72
72
 
73
+ # @return [Array<Ast>]
74
+ def classes
75
+ accumulator=[]
76
+ begin
77
+ return if empty_ast?
78
+ return self if is_class?
79
+ accumulator.concat(children.map {|child| child.classes})
80
+ rescue NoMethodError
81
+ return nil
82
+ end
83
+ accumulator.flatten.compact
84
+ end
85
+
86
+ def to_s
87
+ @ast.to_s
88
+ end
73
89
  end
74
90
  end
@@ -5,7 +5,7 @@ module MetaCommit::Extension::RubySupport::Parsers
5
5
 
6
6
  # @return [Array<String>]
7
7
  def self.supported_file_extensions
8
- ['rb']
8
+ ['.rb']
9
9
  end
10
10
 
11
11
  # @return [Boolean]
@@ -1,7 +1,7 @@
1
1
  module MetaCommit
2
2
  module Extension
3
3
  module RubySupport
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -10,13 +10,13 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["uusername@protonmail.ch"]
11
11
 
12
12
  spec.summary = %q{meta_commit extension adds ruby language support}
13
- spec.homepage = "https://github.com/meta_commit/ruby_support"
13
+ spec.homepage = "https://github.com/meta-commit/ruby_support"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/})}
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_runtime_dependency "meta_commit_contracts", "~> 0.1.2"
19
+ spec.add_runtime_dependency "meta_commit_contracts", "~> 0"
20
20
  spec.add_runtime_dependency "parser", "2.3.0"
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.15"
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3.6"
25
25
  spec.add_development_dependency "rspec-mocks", "~> 3.6"
26
26
  spec.add_development_dependency "coveralls", "~> 0.8"
27
+ spec.add_development_dependency "byebug"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta_commit_ruby_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav Dobrovolskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: meta_commit_contracts
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description:
112
126
  email:
113
127
  - uusername@protonmail.ch
@@ -137,12 +151,13 @@ files:
137
151
  - lib/meta_commit_ruby_support/diffs/module_creation.rb
138
152
  - lib/meta_commit_ruby_support/diffs/module_deletion.rb
139
153
  - lib/meta_commit_ruby_support/diffs/module_rename.rb
154
+ - lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb
140
155
  - lib/meta_commit_ruby_support/locator.rb
141
156
  - lib/meta_commit_ruby_support/models/ast.rb
142
157
  - lib/meta_commit_ruby_support/parsers/ruby.rb
143
158
  - lib/meta_commit_ruby_support/version.rb
144
159
  - meta_commit_ruby_support.gemspec
145
- homepage: https://github.com/meta_commit/ruby_support
160
+ homepage: https://github.com/meta-commit/ruby_support
146
161
  licenses:
147
162
  - MIT
148
163
  metadata: {}
@@ -162,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
177
  version: '0'
163
178
  requirements: []
164
179
  rubyforge_project:
165
- rubygems_version: 2.5.1
180
+ rubygems_version: 2.5.2
166
181
  signing_key:
167
182
  specification_version: 4
168
183
  summary: meta_commit extension adds ruby language support