synvert-core 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +0 -1
- data/lib/synvert/core/configuration.rb +5 -4
- data/lib/synvert/core/rewriter/instance.rb +16 -20
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/configuration_spec.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +18 -15
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9a0f5e143582d26ad70583fece58a3e99251a0bb00af3e2ec1815c8b7163454
|
4
|
+
data.tar.gz: 0e6e001dc795642ddfe0a245339f4632faeb8492f377cb0739c9d0d89b573fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d696b90c59582437c373ea536901c304ef2e63058cb600fd5d9bef731cf8ecc38e021799979174319ed22c1f1e888245f0a9034828953556e3ac09393b8b55af
|
7
|
+
data.tar.gz: bd3db282c2f08918279815aed52e80f8bde651f70f61f5b041094679f1092fac2fee65b92adffa58602b6738f0cd70b8bd2cc0f858c209073200cfd9950c3681
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (2.0
|
4
|
+
synvert-core (2.1.0)
|
5
5
|
activesupport
|
6
6
|
node_mutation (>= 1.24.4)
|
7
7
|
node_query (>= 1.15.3)
|
@@ -59,7 +59,7 @@ GEM
|
|
59
59
|
rb-inotify (~> 0.9, >= 0.9.10)
|
60
60
|
lumberjack (1.2.10)
|
61
61
|
method_source (1.1.0)
|
62
|
-
minitest (5.
|
62
|
+
minitest (5.24.0)
|
63
63
|
mutex_m (0.2.0)
|
64
64
|
nenv (0.3.0)
|
65
65
|
node_mutation (1.24.4)
|
data/README.md
CHANGED
@@ -97,7 +97,6 @@ Actions:
|
|
97
97
|
|
98
98
|
* [append](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#append-instance_method) - append the code to the bottom of current node body
|
99
99
|
* [prepend](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#prepend-instance_method) - prepend the code to the bottom of current node body
|
100
|
-
* [indent](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#indent-instance_method) - indent code
|
101
100
|
* [insert](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert-instance_method) - insert code
|
102
101
|
* [insert_after](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
|
103
102
|
* [insert_before](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
|
@@ -111,10 +111,11 @@ module Synvert::Core
|
|
111
111
|
# # Code to be executed with temporary configurations
|
112
112
|
# end
|
113
113
|
def with_temporary_configurations(configurations, &block)
|
114
|
-
old_instance_variables =
|
115
|
-
hash
|
116
|
-
|
117
|
-
|
114
|
+
old_instance_variables =
|
115
|
+
instance_variables.reduce({}) do |hash, var|
|
116
|
+
hash[var] = instance_variable_get(var)
|
117
|
+
hash
|
118
|
+
end
|
118
119
|
|
119
120
|
configurations.each do |variable, value|
|
120
121
|
instance_variable_set("@#{variable}", value)
|
@@ -391,20 +391,6 @@ module Synvert::Core
|
|
391
391
|
@current_mutation.wrap(@current_node, prefix: prefix, suffix: suffix, newline: newline)
|
392
392
|
end
|
393
393
|
|
394
|
-
# It indent the code of current node.
|
395
|
-
# @example
|
396
|
-
# # class Foobar
|
397
|
-
# # end
|
398
|
-
# # =>
|
399
|
-
# # class Foobar
|
400
|
-
# # end
|
401
|
-
# within_node type: 'class' do
|
402
|
-
# indent
|
403
|
-
# end
|
404
|
-
def indent(tab_size: 1)
|
405
|
-
@current_mutation.indent(@current_node, tab_size: tab_size)
|
406
|
-
end
|
407
|
-
|
408
394
|
# No operation.
|
409
395
|
def noop
|
410
396
|
@current_mutation.noop(@current_node)
|
@@ -466,12 +452,22 @@ module Synvert::Core
|
|
466
452
|
quote + escaped_str + quote
|
467
453
|
end
|
468
454
|
|
469
|
-
#
|
470
|
-
#
|
471
|
-
# @param
|
472
|
-
# @
|
473
|
-
|
474
|
-
|
455
|
+
# Indents the given source code by the specified tab size.
|
456
|
+
#
|
457
|
+
# @param source [String] The source code to be indented.
|
458
|
+
# @param tab_size [Integer] The number of spaces per tab.
|
459
|
+
# @return [String] The indented source code.
|
460
|
+
def indent(source, tab_size: 1)
|
461
|
+
source.each_line.map { |line| (' ' * NodeMutation.tab_width * tab_size) + line }.join
|
462
|
+
end
|
463
|
+
|
464
|
+
# Dedents the given source code by removing leading spaces or tabs.
|
465
|
+
#
|
466
|
+
# @param source [String] The source code to dedent.
|
467
|
+
# @param tab_size [Integer] The number of spaces per tab (default is 1).
|
468
|
+
# @return [String] The dedented source code.
|
469
|
+
def dedent(source, tab_size: 1)
|
470
|
+
source.each_line.map { |line| line.sub(/^ {#{NodeMutation.tab_width * tab_size}}/, '') }.join
|
475
471
|
end
|
476
472
|
|
477
473
|
private
|
data/lib/synvert/core/version.rb
CHANGED
@@ -235,16 +235,6 @@ module Synvert::Core
|
|
235
235
|
instance.wrap prefix: 'module Foobar', suffix: 'end', newline: true
|
236
236
|
end
|
237
237
|
|
238
|
-
it 'parses indent' do
|
239
|
-
instance.instance_variable_set(:@current_mutation, double)
|
240
|
-
instance.current_node = double
|
241
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:indent).with(
|
242
|
-
instance.current_node,
|
243
|
-
tab_size: 1
|
244
|
-
)
|
245
|
-
instance.indent
|
246
|
-
end
|
247
|
-
|
248
238
|
it 'parses noop' do
|
249
239
|
instance.instance_variable_set(:@current_mutation, double)
|
250
240
|
instance.current_node = double
|
@@ -269,7 +259,11 @@ module Synvert::Core
|
|
269
259
|
it 'parsers add_callback' do
|
270
260
|
instance.instance_variable_set(:@current_visitor, double)
|
271
261
|
block = proc {}
|
272
|
-
expect(instance.instance_variable_get(:@current_visitor)).to receive(:add_callback).with(
|
262
|
+
expect(instance.instance_variable_get(:@current_visitor)).to receive(:add_callback).with(
|
263
|
+
:class_node,
|
264
|
+
at: 'start',
|
265
|
+
&block
|
266
|
+
)
|
273
267
|
instance.add_callback(:class_node, at: 'start', &block)
|
274
268
|
end
|
275
269
|
|
@@ -671,10 +665,19 @@ module Synvert::Core
|
|
671
665
|
end
|
672
666
|
end
|
673
667
|
|
674
|
-
describe '#
|
675
|
-
it 'adds
|
676
|
-
|
677
|
-
|
668
|
+
describe '#indent' do
|
669
|
+
it 'adds white spaces' do
|
670
|
+
old_code = "def foo\n bar\nend"
|
671
|
+
new_code = instance.indent(old_code, tab_size: 2)
|
672
|
+
expect(new_code).to eq " def foo\n bar\n end"
|
673
|
+
end
|
674
|
+
end
|
675
|
+
|
676
|
+
describe '#dedent' do
|
677
|
+
it 'removes white spaces' do
|
678
|
+
old_code = " def foo\n bar\n end"
|
679
|
+
new_code = instance.dedent(old_code, tab_size: 2)
|
680
|
+
expect(new_code).to eq "def foo\n bar\nend"
|
678
681
|
end
|
679
682
|
end
|
680
683
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -249,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
249
|
- !ruby/object:Gem::Version
|
250
250
|
version: '0'
|
251
251
|
requirements: []
|
252
|
-
rubygems_version: 3.5.
|
252
|
+
rubygems_version: 3.5.13
|
253
253
|
signing_key:
|
254
254
|
specification_version: 4
|
255
255
|
summary: convert ruby code to better syntax.
|