synvert-core 0.62.0 → 0.62.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e6217815771ca45d3fc81030b42ae126252ab800e127518e72c2f2b4dd2eb5c
4
- data.tar.gz: 266cc5cda364f6df8100a290d393f879075b433acfd7ee70c780b37d23a83292
3
+ metadata.gz: 79777679e6001f32c8b4bc587e2f007f396eeecd9c0c7e29926e01a3628b4244
4
+ data.tar.gz: df4d3eda62e9b2f49ec1cf8da96bd98952d7d5af70fd4d6861b206bbc923cca9
5
5
  SHA512:
6
- metadata.gz: 89c3f93da22298305839c57fadb4963ea0973e16de10b2d2260c76e63927d25c302bbcd2c74515e79adeb24d2440ecba53025aaeeab0b173c6176adccb5d0875
7
- data.tar.gz: df7a75da7a8bbecee35d4cc1afb862f6aa0184e96d484a6f207a88510dfac70098ea17cca794aefaac0938e37e96d8a91f7ba21738f2f116554238f02344e4c1
6
+ metadata.gz: c9744e62dc972253304018ac041aa1f4cd01efd8a80a207a77145e088d4d69713ef4ec10ade9fe4d251811b6a8166d8e33b575ea91265fbec4f989a9e29ac376
7
+ data.tar.gz: cad73e2d256e25370b535a0f623fee47c02f4d5a56e3feaed50f81a798cf3c1dbb0ffd4d6ad04ab167be78fc390703a2a01f0377b79ea621f1674399aa2c7534
@@ -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
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.62.1 (2022-01-14)
4
+
5
+ * Add `to` option to `InsertAction`
6
+
3
7
  ## 0.62.0 (2021-12-24)
4
8
 
5
9
  * Support `csend` node
@@ -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
- @begin_pos = @at == 'end' ? @node.loc.expression.end_pos : @node.loc.expression.begin_pos
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
- def insert(code, at: 'end')
244
- @actions << Rewriter::InsertAction.new(self, code, at: at).process
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.62.0'
5
+ VERSION = '0.62.1'
6
6
  end
7
7
  end
data/lib/synvert/core.rb CHANGED
@@ -5,6 +5,7 @@ require 'bundler'
5
5
  require 'parser'
6
6
  require 'parser/current'
7
7
  require 'ast'
8
+ require 'active_support'
8
9
  require 'active_support/core_ext/object'
9
10
  require 'active_support/core_ext/array'
10
11
  require 'erubis'
@@ -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
@@ -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", "~> 6"
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.0
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: 2021-12-24 00:00:00.000000000 Z
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: '6'
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: '6'
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.2.22
221
+ rubygems_version: 3.3.3
222
222
  signing_key:
223
223
  specification_version: 4
224
224
  summary: convert ruby code to better syntax.