synvert-core 0.62.0 → 0.62.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 +4 -4
- data/.github/workflows/main.yml +2 -2
- data/CHANGELOG.md +4 -0
- data/lib/synvert/core/rewriter/action/insert_action.rb +4 -2
- data/lib/synvert/core/rewriter/instance.rb +3 -2
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +1 -0
- data/spec/synvert/core/rewriter/action/insert_action_spec.rb +21 -0
- data/spec/synvert/core/rewriter/instance_spec.rb +3 -3
- data/synvert-core-ruby.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79777679e6001f32c8b4bc587e2f007f396eeecd9c0c7e29926e01a3628b4244
|
4
|
+
data.tar.gz: df4d3eda62e9b2f49ec1cf8da96bd98952d7d5af70fd4d6861b206bbc923cca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9744e62dc972253304018ac041aa1f4cd01efd8a80a207a77145e088d4d69713ef4ec10ade9fe4d251811b6a8166d8e33b575ea91265fbec4f989a9e29ac376
|
7
|
+
data.tar.gz: cad73e2d256e25370b535a0f623fee47c02f4d5a56e3feaed50f81a798cf3c1dbb0ffd4d6ad04ab167be78fc390703a2a01f0377b79ea621f1674399aa2c7534
|
data/.github/workflows/main.yml
CHANGED
@@ -19,7 +19,7 @@ jobs:
|
|
19
19
|
runs-on: ubuntu-latest
|
20
20
|
strategy:
|
21
21
|
matrix:
|
22
|
-
ruby-version: ['2.5', '2.6', '2.7', '3.0']
|
22
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
|
23
23
|
|
24
24
|
steps:
|
25
25
|
- uses: actions/checkout@v2
|
@@ -29,4 +29,4 @@ jobs:
|
|
29
29
|
ruby-version: ${{ matrix.ruby-version }}
|
30
30
|
bundler-cache: true
|
31
31
|
- name: Run tests
|
32
|
-
run: bundle exec rake
|
32
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -3,13 +3,15 @@
|
|
3
3
|
module Synvert::Core
|
4
4
|
# InsertAction to add code to the node.
|
5
5
|
class Rewriter::InsertAction < Rewriter::Action
|
6
|
-
def initialize(instance, code, at:)
|
6
|
+
def initialize(instance, code, at:, to: nil)
|
7
7
|
super(instance, code)
|
8
8
|
@at = at
|
9
|
+
@to = to
|
9
10
|
end
|
10
11
|
|
11
12
|
def calculate_position
|
12
|
-
|
13
|
+
node_range = @to ? @node.child_node_range(@to) : @node.loc.expression
|
14
|
+
@begin_pos = @at == 'end' ? node_range.end_pos : node_range.begin_pos
|
13
15
|
@end_pos = @begin_pos
|
14
16
|
end
|
15
17
|
|
@@ -240,8 +240,9 @@ module Synvert::Core
|
|
240
240
|
#
|
241
241
|
# @param code [String] code need to be inserted.
|
242
242
|
# @param at [String] insert position, beginning or end, end is the default.
|
243
|
-
|
244
|
-
|
243
|
+
# @param to [String] where to insert, if it is nil, will insert to current node.
|
244
|
+
def insert(code, at: 'end', to: nil)
|
245
|
+
@actions << Rewriter::InsertAction.new(self, code, at: at, to: to).process
|
245
246
|
end
|
246
247
|
|
247
248
|
# Parse insert_after dsl, it creates a [Synvert::Core::Rewriter::InsertAfterAction] to
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
@@ -45,5 +45,26 @@ module Synvert::Core
|
|
45
45
|
expect(subject.rewritten_code).to eq 'URI.'
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
context 'to receiver' do
|
50
|
+
subject {
|
51
|
+
source = "User.where(username: 'Richard')"
|
52
|
+
node = Parser::CurrentRuby.parse(source)
|
53
|
+
instance = double(current_node: node)
|
54
|
+
Rewriter::InsertAction.new(instance, '.active', to: 'receiver', at: 'end').process
|
55
|
+
}
|
56
|
+
|
57
|
+
it 'gets begin_pos' do
|
58
|
+
expect(subject.begin_pos).to eq "User".length
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'gets end_pos' do
|
62
|
+
expect(subject.end_pos).to eq "User".length
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'gets rewritten_code' do
|
66
|
+
expect(subject.rewritten_code).to eq '.active'
|
67
|
+
end
|
68
|
+
end
|
48
69
|
end
|
49
70
|
end
|
@@ -118,14 +118,14 @@ module Synvert::Core
|
|
118
118
|
|
119
119
|
it 'parses insert at end' do
|
120
120
|
action = double
|
121
|
-
expect(Rewriter::InsertAction).to receive(:new).with(instance, '.first', at: 'end').and_return(action)
|
121
|
+
expect(Rewriter::InsertAction).to receive(:new).with(instance, '.first', at: 'end', to: 'receiver').and_return(action)
|
122
122
|
expect(action).to receive(:process)
|
123
|
-
instance.insert '.first'
|
123
|
+
instance.insert '.first', to: 'receiver'
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'parses insert at beginning' do
|
127
127
|
action = double
|
128
|
-
expect(Rewriter::InsertAction).to receive(:new).with(instance, 'URI.', at: 'beginning').and_return(action)
|
128
|
+
expect(Rewriter::InsertAction).to receive(:new).with(instance, 'URI.', at: 'beginning', to: nil).and_return(action)
|
129
129
|
expect(action).to receive(:process)
|
130
130
|
instance.insert 'URI.', at: 'beginning'
|
131
131
|
end
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "activesupport"
|
22
|
+
spec.add_runtime_dependency "activesupport"
|
23
23
|
spec.add_runtime_dependency "erubis"
|
24
24
|
spec.add_runtime_dependency "parser"
|
25
25
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.62.
|
4
|
+
version: 0.62.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: erubis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
- !ruby/object:Gem::Version
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
221
|
+
rubygems_version: 3.3.3
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: convert ruby code to better syntax.
|