synvert-core 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -3
- data/Guardfile +0 -9
- data/README.md +30 -12
- data/Rakefile +1 -15
- data/lib/synvert/core/engine/erb.rb +1 -1
- data/lib/synvert/core/engine.rb +1 -1
- data/lib/synvert/core/node_ext.rb +0 -466
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
- data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/instance.rb +83 -133
- data/lib/synvert/core/rewriter/scope/query_scope.rb +2 -2
- data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -4
- data/lib/synvert/core/rewriter.rb +0 -10
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +4 -6
- data/spec/synvert/core/engine/erb_spec.rb +3 -3
- data/spec/synvert/core/node_ext_spec.rb +0 -795
- data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +47 -115
- data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
- data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +1 -4
- data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +1 -4
- data/synvert-core-ruby.gemspec +4 -2
- metadata +44 -61
- data/lib/synvert/core/array_ext.rb +0 -48
- data/lib/synvert/core/node_query/compiler/array.rb +0 -34
- data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
- data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
- data/lib/synvert/core/node_query/compiler/basic_selector.rb +0 -28
- data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
- data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
- data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
- data/lib/synvert/core/node_query/compiler/expression.rb +0 -41
- data/lib/synvert/core/node_query/compiler/float.rb +0 -23
- data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
- data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
- data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
- data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
- data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
- data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
- data/lib/synvert/core/node_query/compiler/selector.rb +0 -113
- data/lib/synvert/core/node_query/compiler/string.rb +0 -23
- data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
- data/lib/synvert/core/node_query/compiler.rb +0 -25
- data/lib/synvert/core/node_query/lexer.rex +0 -99
- data/lib/synvert/core/node_query/lexer.rex.rb +0 -299
- data/lib/synvert/core/node_query/parser.racc.rb +0 -306
- data/lib/synvert/core/node_query/parser.y +0 -60
- data/lib/synvert/core/node_query.rb +0 -36
- data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
- data/lib/synvert/core/rewriter/action/delete_action.rb +0 -34
- data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
- data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
- data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
- data/lib/synvert/core/rewriter/action/remove_action.rb +0 -56
- data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
- data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
- data/lib/synvert/core/rewriter/action.rb +0 -102
- data/spec/synvert/core/node_query/lexer_spec.rb +0 -580
- data/spec/synvert/core/node_query/parser_spec.rb +0 -337
- data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
- data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
- data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
- data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
- data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
- data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
- data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
- data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
- data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
- data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Synvert::Core
|
6
|
-
describe Rewriter::RemoveAction do
|
7
|
-
subject {
|
8
|
-
source = "user = User.new params[:user]\nuser.save\nrender\n"
|
9
|
-
send_node = Parser::CurrentRuby.parse(source).children[1]
|
10
|
-
instance = double(current_node: send_node, file_source: source)
|
11
|
-
Rewriter::RemoveAction.new(instance).process
|
12
|
-
}
|
13
|
-
|
14
|
-
it 'gets begin_pos' do
|
15
|
-
expect(subject.begin_pos).to eq "user = User.new params[:user]\n".length
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'gets end_pos' do
|
19
|
-
expect(subject.end_pos).to eq "user = User.new params[:user]\nuser.save\n".length
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'gets rewritten_code' do
|
23
|
-
expect(subject.rewritten_code).to eq ''
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Synvert::Core
|
6
|
-
describe Rewriter::ReplaceAction do
|
7
|
-
context 'replace with single line' do
|
8
|
-
subject {
|
9
|
-
source = 'FactoryBot.create(:user)'
|
10
|
-
node = Parser::CurrentRuby.parse(source)
|
11
|
-
instance = double(current_node: node)
|
12
|
-
Rewriter::ReplaceAction.new(instance, :receiver, :dot, :message, with: 'create').process
|
13
|
-
}
|
14
|
-
|
15
|
-
it 'gets begin_pos' do
|
16
|
-
expect(subject.begin_pos).to eq 0
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'gets end_pos' do
|
20
|
-
expect(subject.end_pos).to eq 'FactoryBot.create'.length
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'gets rewritten_code' do
|
24
|
-
expect(subject.rewritten_code).to eq 'create'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Synvert::Core
|
6
|
-
describe Rewriter::ReplaceWithAction do
|
7
|
-
context 'replace with single line' do
|
8
|
-
subject {
|
9
|
-
source = 'post = FactoryGirl.create_list :post, 2'
|
10
|
-
send_node = Parser::CurrentRuby.parse(source).children[1]
|
11
|
-
instance = double(current_node: send_node)
|
12
|
-
Rewriter::ReplaceWithAction.new(instance, 'create_list {{arguments}}').process
|
13
|
-
}
|
14
|
-
|
15
|
-
it 'gets begin_pos' do
|
16
|
-
expect(subject.begin_pos).to eq 'post = '.length
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'gets end_pos' do
|
20
|
-
expect(subject.end_pos).to eq 'post = FactoryGirl.create_list :post, 2'.length
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'gets rewritten_code' do
|
24
|
-
expect(subject.rewritten_code).to eq 'create_list :post, 2'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context '#replace with multiple line' do
|
29
|
-
subject {
|
30
|
-
source = ' its(:size) { should == 1 }'
|
31
|
-
send_node = Parser::CurrentRuby.parse(source)
|
32
|
-
instance = double(current_node: send_node)
|
33
|
-
Rewriter::ReplaceWithAction.new(instance, <<~EOS).process
|
34
|
-
describe '#size' do
|
35
|
-
subject { super().size }
|
36
|
-
it { {{body}} }
|
37
|
-
end
|
38
|
-
EOS
|
39
|
-
}
|
40
|
-
|
41
|
-
it 'gets begin_pos' do
|
42
|
-
expect(subject.begin_pos).to eq 2
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'gets end_pos' do
|
46
|
-
expect(subject.end_pos).to eq ' its(:size) { should == 1 }'.length
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'gets rewritten_code' do
|
50
|
-
expect(subject.rewritten_code).to eq <<~EOS.strip
|
51
|
-
describe '#size' do
|
52
|
-
subject { super().size }
|
53
|
-
it { should == 1 }
|
54
|
-
end
|
55
|
-
EOS
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Synvert::Core
|
6
|
-
describe Rewriter::WrapAction do
|
7
|
-
subject {
|
8
|
-
source = "class Bar\nend"
|
9
|
-
node = Parser::CurrentRuby.parse(source)
|
10
|
-
instance = double(current_node: node)
|
11
|
-
Rewriter::WrapAction.new(instance, with: 'module Foo').process
|
12
|
-
}
|
13
|
-
|
14
|
-
it 'gets begin_pos' do
|
15
|
-
expect(subject.begin_pos).to eq 0
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'gets end_pos' do
|
19
|
-
expect(subject.end_pos).to eq "class Bar\nend".length
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'gets rewritten_code' do
|
23
|
-
expect(subject.rewritten_code).to eq <<~EOS.strip
|
24
|
-
module Foo
|
25
|
-
class Bar
|
26
|
-
end
|
27
|
-
end
|
28
|
-
EOS
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Synvert::Core
|
6
|
-
describe Rewriter::Action do
|
7
|
-
subject {
|
8
|
-
source = "before_save do\n return false\nend"
|
9
|
-
block_node = Parser::CurrentRuby.parse(source).body.first
|
10
|
-
instance = double(current_node: block_node)
|
11
|
-
Rewriter::Action.new(instance, source)
|
12
|
-
}
|
13
|
-
end
|
14
|
-
end
|