Class: MetaCommit::Extension::RubySupport::Diffs::Diff
- Inherits:
-
Contracts::Diff
- Object
- Contracts::Diff
- MetaCommit::Extension::RubySupport::Diffs::Diff
show all
- Defined in:
- lib/meta_commit_ruby_support/diffs/diff.rb
Overview
Constant Summary
collapse
- TYPE_ADDITION =
:addition
- TYPE_DELETION =
:deletion
- TYPE_REPLACE =
:replace
- SUPPORTED_PARSERS =
[MetaCommit::Extension::RubySupport::Parsers::Ruby]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#commit_new ⇒ String
Returns the current value of commit_new.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def commit_new
@commit_new
end
|
#commit_old ⇒ String
Returns the current value of commit_old.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def commit_old
@commit_old
end
|
#diff_type ⇒ Symbol
Returns the current value of diff_type.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def diff_type
@diff_type
end
|
#new_ast_path ⇒ MetaCommit::Models::ContextualAstNode
Returns the current value of new_ast_path.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def new_ast_path
@new_ast_path
end
|
#new_file ⇒ String
Returns the current value of new_file.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def new_file
@new_file
end
|
#new_lineno ⇒ String
Returns the current value of new_lineno.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def new_lineno
@new_lineno
end
|
#old_ast_path ⇒ MetaCommit::Models::ContextualAstNode
Returns the current value of old_ast_path.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def old_ast_path
@old_ast_path
end
|
#old_file ⇒ String
Returns the current value of old_file.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def old_file
@old_file
end
|
#old_lineno ⇒ String
Returns the current value of old_lineno.
12
13
14
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 12
def old_lineno
@old_lineno
end
|
Instance Method Details
#inspect ⇒ String
42
43
44
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 42
def inspect
string_representation
end
|
#is_in_context_of_class?(ast) ⇒ Boolean
128
129
130
131
132
133
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 128
def is_in_context_of_class?(ast)
ast.context_nodes.each do |parent|
return true if parent.is_class?
end
false
end
|
#is_in_context_of_method?(ast) ⇒ Boolean
137
138
139
140
141
142
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 137
def is_in_context_of_method?(ast)
ast.context_nodes.each do |parent|
return true if parent.is_method?
end
false
end
|
#is_in_context_of_module?(ast) ⇒ Boolean
119
120
121
122
123
124
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 119
def is_in_context_of_module?(ast)
ast.context_nodes.each do |parent|
return true if parent.is_module?
end
false
end
|
#is_name_of_class?(ast) ⇒ Boolean
on created class only first line goes to diff
86
87
88
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 86
def is_name_of_class?(ast)
(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)
end
|
#is_name_of_module?(ast) ⇒ Boolean
on created module only first line goes to diff
92
93
94
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 92
def is_name_of_module?(ast)
(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)
end
|
#name_of_context_class(ast) ⇒ Object
104
105
106
107
108
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 104
def name_of_context_class(ast)
ast.context_nodes.reverse.each do |parent|
return parent.class_name if parent.is_class?
end
end
|
#name_of_context_method(ast) ⇒ Object
111
112
113
114
115
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 111
def name_of_context_method(ast)
ast.context_nodes.reverse.each do |parent|
return parent.method_name if parent.is_method?
end
end
|
#name_of_context_module(ast) ⇒ Object
97
98
99
100
101
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 97
def name_of_context_module(ast)
ast.context_nodes.reverse.each do |parent|
return parent.module_name if parent.is_module?
end
end
|
#path_to_component(ast, depth = nil) ⇒ String
75
76
77
78
79
80
81
82
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 75
def path_to_component(ast, depth=nil)
depth = -1 if depth.nil?
result = []
result.concat([name_of_context_module(ast), is_in_context_of_class?(ast) && depth < 1 ? '::' : '']) if is_in_context_of_module?(ast) && depth < 2
result.concat([name_of_context_class(ast)]) if is_in_context_of_class?(ast) && depth < 1
result.concat(['#', name_of_context_method(ast)]) if is_in_context_of_method?(ast) && depth < 0
result.join('')
end
|
#string_representation ⇒ String
52
53
54
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 52
def string_representation
"#{diff_type} was performed"
end
|
#supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path) ⇒ Boolean
37
38
39
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 37
def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
true
end
|
#supports_parser?(parser) ⇒ Boolean
27
28
29
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 27
def supports_parser?(parser)
SUPPORTED_PARSERS.include?(parser)
end
|
#to_s ⇒ String
47
48
49
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 47
def to_s
string_representation
end
|
#type_addition? ⇒ Boolean
57
58
59
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 57
def type_addition?
@diff_type == TYPE_ADDITION
end
|
#type_deletion? ⇒ Boolean
62
63
64
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 62
def type_deletion?
@diff_type == TYPE_DELETION
end
|
#type_replace? ⇒ Boolean
67
68
69
|
# File 'lib/meta_commit_ruby_support/diffs/diff.rb', line 67
def type_replace?
@diff_type == TYPE_REPLACE
end
|