synvert-core 0.18.0 → 0.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/CHANGELOG.md +18 -0
- data/lib/synvert/core/configuration.rb +9 -17
- data/lib/synvert/core/engine/erb.rb +15 -13
- data/lib/synvert/core/node_ext.rb +8 -8
- data/lib/synvert/core/rewriter.rb +24 -12
- data/lib/synvert/core/rewriter/condition.rb +1 -1
- 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/gem_spec.rb +3 -2
- data/lib/synvert/core/rewriter/helper.rb +17 -1
- data/lib/synvert/core/rewriter/instance.rb +5 -5
- data/lib/synvert/core/rewriter/ruby_version.rb +1 -3
- data/lib/synvert/core/rewriter/scope/goto_scope.rb +1 -1
- data/lib/synvert/core/rewriter/scope/within_scope.rb +3 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/spec_helper.rb +0 -5
- data/spec/synvert/core/node_ext_spec.rb +1 -1
- data/spec/synvert/core/rewriter/helper_spec.rb +12 -0
- data/spec/synvert/core/rewriter/ruby_version_spec.rb +17 -0
- data/spec/synvert/core/rewriter_spec.rb +6 -0
- data/synvert-core.gemspec +8 -7
- metadata +19 -19
- data/spec/synvert/core/configuration_spec.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945aecfd794891da0a5fc8d5a1ac1f03946090c7bb01ff458545292a91296160
|
4
|
+
data.tar.gz: d0e863e0fdeda70cba509a84a44a3665de4edabb178bdb38aa3649095d0b4c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b328ae8b13f6c056d18f59fdd643bab5e97aba335f34b9b0d50ef558f5b74a4ed14549c19675495bd213d852db09a3bbf2da8fc95abfa2cb3f833b06e2aca50a
|
7
|
+
data.tar.gz: 92050432ab95a2cec0cbbfa3b54f12101880da2f856935537e85fef43e196c8f560d78b2d06f6ed26e866c64bf889ded1b4d1b4e88c04ac4b4f0df6f6c16cb31
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.21.1 (2021-02-26)
|
4
|
+
|
5
|
+
* Fix `find_matching_nodes` if `current_node` is a `Parser::AST::Node`
|
6
|
+
|
7
|
+
## 0.21.0 (2021-02-25)
|
8
|
+
|
9
|
+
* Set `env['BUNDLE_GEMFILE']` before parsing `Gemfile.lock`
|
10
|
+
* Add `Rewriter::RubyVersion` test
|
11
|
+
* Add `reject_keys_from_hash` helper method
|
12
|
+
|
13
|
+
## 0.20.0 (2021-02-15)
|
14
|
+
|
15
|
+
* Call snippet in sandbox mode
|
16
|
+
|
17
|
+
## 0.19.0 (2021-02-07)
|
18
|
+
|
19
|
+
* Simplify `Configuration`
|
20
|
+
|
3
21
|
## 0.18.0 (2021-02-07)
|
4
22
|
|
5
23
|
* Add `Rewriter.execute`
|
@@ -1,26 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'singleton'
|
4
|
-
|
5
3
|
module Synvert::Core
|
6
4
|
# Synvert global configuration.
|
7
|
-
class Configuration
|
8
|
-
|
5
|
+
class Configuration
|
6
|
+
class << self
|
7
|
+
attr_writer :path, :skip_files
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# @param value [Object] configuration value.
|
14
|
-
def set(key, value)
|
15
|
-
self[key] = value
|
16
|
-
end
|
9
|
+
def path
|
10
|
+
@path || '.'
|
11
|
+
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# @return [Object] configuration value.
|
22
|
-
def get(key)
|
23
|
-
self[key]
|
13
|
+
def skip_files
|
14
|
+
@skip_files || []
|
15
|
+
end
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
@@ -31,21 +31,23 @@ module Synvert::Core
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def decode_ruby_stmt(source)
|
34
|
-
source.gsub(/#{ERUBY_STMT_SPLITTER}(.+?)#{ERUBY_STMT_SPLITTER}/
|
34
|
+
source.gsub(/#{ERUBY_STMT_SPLITTER}(.+?)#{ERUBY_STMT_SPLITTER}/mo) { "<%#{Regexp.last_match(1)}%>" }
|
35
35
|
end
|
36
36
|
|
37
37
|
def decode_ruby_output(source)
|
38
|
-
source.gsub(/@output_buffer.append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/
|
39
|
-
|
40
|
-
|
38
|
+
source.gsub(/@output_buffer.append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/mo) {
|
39
|
+
"<%=#{Regexp.last_match(1)}%>"
|
40
|
+
}.gsub(/@output_buffer.append= (.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/mo) { |m|
|
41
|
+
"<%=#{m.sub('@output_buffer.append= ', '').sub(ERUBY_EXPR_SPLITTER, '')}%>"
|
42
|
+
}
|
41
43
|
end
|
42
44
|
|
43
45
|
def decode_html_output(source)
|
44
|
-
source.gsub(/@output_buffer.safe_append='(.+?)'.freeze;/m) { reverse_escape_text(
|
45
|
-
/@output_buffer.safe_append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/
|
46
|
-
) { reverse_escape_text(
|
47
|
-
/@output_buffer.safe_append=(.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/
|
48
|
-
) { reverse_escape_text(
|
46
|
+
source.gsub(/@output_buffer.safe_append='(.+?)'.freeze;/m) { reverse_escape_text(Regexp.last_match(1)) }.gsub(
|
47
|
+
/@output_buffer.safe_append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/mo
|
48
|
+
) { reverse_escape_text(Regexp.last_match(1)) }.gsub(
|
49
|
+
/@output_buffer.safe_append=(.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/mo
|
50
|
+
) { reverse_escape_text(Regexp.last_match(1)) }
|
49
51
|
end
|
50
52
|
|
51
53
|
def remove_erubis_buf(source)
|
@@ -97,7 +99,7 @@ module Synvert::Core
|
|
97
99
|
|
98
100
|
def add_expr_literal(src, code)
|
99
101
|
flush_newline_if_pending(src)
|
100
|
-
if code
|
102
|
+
if BLOCK_EXPR.match?(code)
|
101
103
|
src << '@output_buffer.append= ' << code << ERUBY_EXPR_SPLITTER
|
102
104
|
else
|
103
105
|
src << '@output_buffer.append=(' << code << ');' << ERUBY_EXPR_SPLITTER
|
@@ -106,7 +108,7 @@ module Synvert::Core
|
|
106
108
|
|
107
109
|
def add_expr_escaped(src, code)
|
108
110
|
flush_newline_if_pending(src)
|
109
|
-
if code
|
111
|
+
if BLOCK_EXPR.match?(code)
|
110
112
|
src << '@output_buffer.safe_append= ' << code << ERUBY_EXPR_SPLITTER
|
111
113
|
else
|
112
114
|
src << '@output_buffer.safe_append=(' << code << ');' << ERUBY_EXPR_SPLITTER
|
@@ -119,9 +121,9 @@ module Synvert::Core
|
|
119
121
|
index =
|
120
122
|
case code
|
121
123
|
when /\A(\s*)\r?\n/
|
122
|
-
|
124
|
+
Regexp.last_match(1).length
|
123
125
|
when /\A(\s+)/
|
124
|
-
|
126
|
+
Regexp.last_match(1).end_with?(' ') ? Regexp.last_match(1).length - 1 : Regexp.last_match(1).length
|
125
127
|
else
|
126
128
|
0
|
127
129
|
end
|
@@ -321,11 +321,11 @@ module Parser::AST
|
|
321
321
|
#
|
322
322
|
# @yield [child] Gives a child node.
|
323
323
|
# @yieldparam child [Parser::AST::Node] child node
|
324
|
-
def recursive_children
|
324
|
+
def recursive_children(&block)
|
325
325
|
children.each do |child|
|
326
|
-
if Parser::AST::Node
|
326
|
+
if child.is_a?(Parser::AST::Node)
|
327
327
|
yield child
|
328
|
-
child.recursive_children
|
328
|
+
child.recursive_children(&block)
|
329
329
|
end
|
330
330
|
end
|
331
331
|
end
|
@@ -364,7 +364,7 @@ module Parser::AST
|
|
364
364
|
# @raise [Synvert::Core::MethodNotSupported] if string in block {{ }} does not support.
|
365
365
|
def rewritten_source(code)
|
366
366
|
code.gsub(/{{(.*?)}}/m) do
|
367
|
-
old_code =
|
367
|
+
old_code = Regexp.last_match(1)
|
368
368
|
if respond_to? old_code.split(/\.|\[/).first
|
369
369
|
evaluated = instance_eval old_code
|
370
370
|
case evaluated
|
@@ -410,20 +410,20 @@ module Parser::AST
|
|
410
410
|
def match_value?(actual, expected)
|
411
411
|
case expected
|
412
412
|
when Symbol
|
413
|
-
if Parser::AST::Node
|
413
|
+
if actual.is_a?(Parser::AST::Node)
|
414
414
|
actual.to_source == ":#{expected}"
|
415
415
|
else
|
416
416
|
actual.to_sym == expected
|
417
417
|
end
|
418
418
|
when String
|
419
|
-
if Parser::AST::Node
|
419
|
+
if actual.is_a?(Parser::AST::Node)
|
420
420
|
actual.to_source == expected || (actual.to_source[0] == ':' && actual.to_source[1..-1] == expected) ||
|
421
421
|
actual.to_source[1...-1] == expected
|
422
422
|
else
|
423
423
|
actual.to_s == expected
|
424
424
|
end
|
425
425
|
when Regexp
|
426
|
-
if Parser::AST::Node
|
426
|
+
if actual.is_a?(Parser::AST::Node)
|
427
427
|
actual.to_source =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
|
428
428
|
else
|
429
429
|
actual.to_s =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
|
@@ -435,7 +435,7 @@ module Parser::AST
|
|
435
435
|
when NilClass
|
436
436
|
actual.nil?
|
437
437
|
when Numeric
|
438
|
-
if Parser::AST::Node
|
438
|
+
if actual.is_a?(Parser::AST::Node)
|
439
439
|
actual.children[0] == expected
|
440
440
|
else
|
441
441
|
actual == expected
|
@@ -56,7 +56,8 @@ module Synvert::Core
|
|
56
56
|
# @param name [String] the unique rewriter name.
|
57
57
|
# @param rewriter [Synvert::Core::Rewriter] the rewriter to register.
|
58
58
|
def register(group, name, rewriter)
|
59
|
-
group
|
59
|
+
group = group.to_s
|
60
|
+
name = name.to_s
|
60
61
|
rewriters[group] ||= {}
|
61
62
|
rewriters[group][name] = rewriter
|
62
63
|
end
|
@@ -68,7 +69,8 @@ module Synvert::Core
|
|
68
69
|
# @return [Synvert::Core::Rewriter] the matching rewriter.
|
69
70
|
# @raise [Synvert::Core::RewriterNotFound] if the registered rewriter is not found.
|
70
71
|
def fetch(group, name)
|
71
|
-
group
|
72
|
+
group = group.to_s
|
73
|
+
name = name.to_s
|
72
74
|
if exist? group, name
|
73
75
|
rewriters[group][name]
|
74
76
|
else
|
@@ -80,13 +82,19 @@ module Synvert::Core
|
|
80
82
|
#
|
81
83
|
# @param group [String] the rewriter group.
|
82
84
|
# @param name [String] the rewriter name.
|
85
|
+
# @param sandbox [Boolean] if run in sandbox mode, default is false.
|
83
86
|
# @return [Synvert::Core::Rewriter] the registered rewriter.
|
84
87
|
# @raise [Synvert::Core::RewriterNotFound] if the registered rewriter is not found.
|
85
|
-
def call(group, name)
|
86
|
-
group
|
88
|
+
def call(group, name, sandbox = false)
|
89
|
+
group = group.to_s
|
90
|
+
name = name.to_s
|
87
91
|
if exist? group, name
|
88
92
|
rewriter = rewriters[group][name]
|
89
|
-
|
93
|
+
if sandbox
|
94
|
+
rewriter.process_with_sandbox
|
95
|
+
else
|
96
|
+
rewriter.process
|
97
|
+
end
|
90
98
|
rewriter
|
91
99
|
else
|
92
100
|
raise RewriterNotFound, "Rewriter #{group}/#{name} not found"
|
@@ -99,7 +107,8 @@ module Synvert::Core
|
|
99
107
|
# @param name [String] the rewriter name.
|
100
108
|
# @return [Boolean] true if the rewriter exist.
|
101
109
|
def exist?(group, name)
|
102
|
-
group
|
110
|
+
group = group.to_s
|
111
|
+
name = name.to_s
|
103
112
|
if rewriters[group] && rewriters[group][name]
|
104
113
|
true
|
105
114
|
else
|
@@ -158,15 +167,18 @@ module Synvert::Core
|
|
158
167
|
# Process the rewriter.
|
159
168
|
# It will call the block.
|
160
169
|
def process
|
161
|
-
instance_eval
|
170
|
+
instance_eval(&@block)
|
162
171
|
end
|
163
172
|
|
164
173
|
# Process rewriter with sandbox mode.
|
165
174
|
# It will call the block but doesn't change any file.
|
166
175
|
def process_with_sandbox
|
167
176
|
@sandbox = true
|
168
|
-
|
169
|
-
|
177
|
+
begin
|
178
|
+
process
|
179
|
+
ensure
|
180
|
+
@sandbox = false
|
181
|
+
end
|
170
182
|
end
|
171
183
|
|
172
184
|
# Add a warning.
|
@@ -233,7 +245,7 @@ module Synvert::Core
|
|
233
245
|
def add_file(filename, content)
|
234
246
|
return if @sandbox
|
235
247
|
|
236
|
-
filepath = File.join(Configuration.
|
248
|
+
filepath = File.join(Configuration.path, filename)
|
237
249
|
if File.exist?(filepath)
|
238
250
|
puts "File #{filepath} already exists."
|
239
251
|
return
|
@@ -251,7 +263,7 @@ module Synvert::Core
|
|
251
263
|
def remove_file(filename)
|
252
264
|
return if @sandbox
|
253
265
|
|
254
|
-
file_path = File.join(Configuration.
|
266
|
+
file_path = File.join(Configuration.path, filename)
|
255
267
|
File.delete(file_path) if File.exist?(file_path)
|
256
268
|
end
|
257
269
|
|
@@ -260,7 +272,7 @@ module Synvert::Core
|
|
260
272
|
# @param group [String] group of another rewriter.
|
261
273
|
# @param name [String] name of another rewriter.
|
262
274
|
def add_snippet(group, name)
|
263
|
-
@sub_snippets << self.class.call(group.to_s, name.to_s)
|
275
|
+
@sub_snippets << self.class.call(group.to_s, name.to_s, @sandbox)
|
264
276
|
end
|
265
277
|
|
266
278
|
# Parse helper_method dsl, it defines helper method for [Synvert::Core::Rewriter::Instance].
|
@@ -12,7 +12,7 @@ module Synvert::Core
|
|
12
12
|
# comparator key can be eq, lt, gt, lte, gte or ne.
|
13
13
|
def initialize(name, comparator)
|
14
14
|
@name = name
|
15
|
-
if Hash
|
15
|
+
if comparator.is_a?(Hash)
|
16
16
|
@operator = comparator.keys.first
|
17
17
|
@version = Gem::Version.new comparator.values.first
|
18
18
|
else
|
@@ -26,11 +26,12 @@ module Synvert::Core
|
|
26
26
|
# @return [Boolean] true if matches, otherwise false.
|
27
27
|
# @raise [Synvert::Core::GemfileLockNotFound] raise if Gemfile.lock does not exist.
|
28
28
|
def match?
|
29
|
-
gemfile_lock_path = File.join(Configuration.
|
29
|
+
gemfile_lock_path = File.join(Configuration.path, 'Gemfile.lock')
|
30
30
|
|
31
31
|
# if Gemfile.lock does not exist, just ignore this check
|
32
32
|
return true unless File.exist?(gemfile_lock_path)
|
33
33
|
|
34
|
+
ENV['BUNDLE_GEMFILE'] = Configuration.path # make sure bundler reads Gemfile.lock in the correct path
|
34
35
|
parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path))
|
35
36
|
if spec = parser.specs.find { |spec| spec.name == @name }
|
36
37
|
Gem::Version.new(spec.version).send(OPERATORS[@operator], @version)
|
@@ -65,7 +65,23 @@ module Synvert::Core
|
|
65
65
|
#
|
66
66
|
# strip_brackets("(1..100)") #=> "1..100"
|
67
67
|
def strip_brackets(code)
|
68
|
-
code.sub(/^\((.*)\)$/) {
|
68
|
+
code.sub(/^\((.*)\)$/) { Regexp.last_match(1) }.sub(/^\[(.*)\]$/) { Regexp.last_match(1) }.sub(/^{(.*)}$/) {
|
69
|
+
Regexp.last_match(1)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
# Reject some keys from hash node.
|
74
|
+
#
|
75
|
+
# @param hash_node [Parser::AST::Node]
|
76
|
+
# @param keys [Array] keys should be rejected from the hash.
|
77
|
+
# @return [String] source of of the hash node after rejecting some keys.
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
#
|
81
|
+
# hash_node = Parser::CurrentRuby.parse("{ key1: 'value1', key2: 'value2' }")
|
82
|
+
# reject_keys_from_hash(hash_node, :key1) => "key2: 'value2'"
|
83
|
+
def reject_keys_from_hash(hash_node, *keys)
|
84
|
+
hash_node.children.reject { |pair_node| keys.include?(pair_node.key.to_value) }.map(&:to_source).join(', ')
|
69
85
|
end
|
70
86
|
end
|
71
87
|
end
|
@@ -18,7 +18,7 @@ module Synvert::Core
|
|
18
18
|
@file_source[file_path] ||=
|
19
19
|
begin
|
20
20
|
source = File.read(file_path)
|
21
|
-
source = Engine::ERB.encode(source) if
|
21
|
+
source = Engine::ERB.encode(source) if /\.erb$/.match?(file_path)
|
22
22
|
source
|
23
23
|
end
|
24
24
|
end
|
@@ -45,7 +45,7 @@ module Synvert::Core
|
|
45
45
|
# @param file_path [String] file path
|
46
46
|
# @param source [String] file source
|
47
47
|
def write_file(file_path, source)
|
48
|
-
source = Engine::ERB.decode(source) if
|
48
|
+
source = Engine::ERB.decode(source) if /\.erb/.match?(file_path)
|
49
49
|
File.write file_path, source.gsub(/ +\n/, "\n")
|
50
50
|
@file_source[file_path] = nil
|
51
51
|
@file_ast[file_path] = nil
|
@@ -86,11 +86,11 @@ module Synvert::Core
|
|
86
86
|
# It finds all files, for each file, it executes the block code, gets all rewrite actions,
|
87
87
|
# and rewrite source code back to original file.
|
88
88
|
def process
|
89
|
-
file_pattern = File.join(Configuration.
|
89
|
+
file_pattern = File.join(Configuration.path, @file_pattern)
|
90
90
|
Dir
|
91
91
|
.glob(file_pattern)
|
92
92
|
.each do |file_path|
|
93
|
-
next if Configuration.
|
93
|
+
next if Configuration.skip_files.include? file_path
|
94
94
|
|
95
95
|
begin
|
96
96
|
conflict_actions = []
|
@@ -101,7 +101,7 @@ module Synvert::Core
|
|
101
101
|
|
102
102
|
process_with_node ast do
|
103
103
|
begin
|
104
|
-
instance_eval
|
104
|
+
instance_eval(&@block)
|
105
105
|
rescue NoMethodError
|
106
106
|
puts @current_node.debug_info
|
107
107
|
raise
|
@@ -14,9 +14,7 @@ module Synvert::Core
|
|
14
14
|
#
|
15
15
|
# @return [Boolean] true if matches, otherwise false.
|
16
16
|
def match?
|
17
|
-
|
18
|
-
# which is solved from ruby 2.0.0, which calls dup internally.
|
19
|
-
Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new(@version)
|
17
|
+
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(@version)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -26,7 +26,7 @@ module Synvert::Core
|
|
26
26
|
@instance.process_with_node current_node do
|
27
27
|
matching_nodes.each do |matching_node|
|
28
28
|
@instance.process_with_node matching_node do
|
29
|
-
@instance.instance_eval
|
29
|
+
@instance.instance_eval(&@block)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -41,6 +41,8 @@ module Synvert::Core
|
|
41
41
|
current_node.recursive_children do |child_node|
|
42
42
|
matching_nodes << child_node if child_node.match? @rules
|
43
43
|
end
|
44
|
+
elsif current_node.is_a?(Parser::AST::Node)
|
45
|
+
matching_nodes << current_node if current_node.match? @rules
|
44
46
|
else
|
45
47
|
current_node.each do |child_node|
|
46
48
|
matching_nodes << child_node if child_node.match? @rules
|
data/lib/synvert/core/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -80,5 +80,17 @@ module Synvert::Core
|
|
80
80
|
expect(dummy_instance.strip_brackets('(123]')).to eq '(123]'
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe '#reject_keys_from_hash' do
|
85
|
+
it 'rejects single key' do
|
86
|
+
hash_node = Parser::CurrentRuby.parse("{ key1: 'value1', key2: 'value2' }")
|
87
|
+
expect(dummy_instance.reject_keys_from_hash(hash_node, :key1)).to eq "key2: 'value2'"
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'rejects multi keys' do
|
91
|
+
hash_node = Parser::CurrentRuby.parse("{ key1: 'value1', key2: 'value2', key3: 'value3', key4: 'value4' }")
|
92
|
+
expect(dummy_instance.reject_keys_from_hash(hash_node, :key1, :key3)).to eq "key2: 'value2', key4: 'value4'"
|
93
|
+
end
|
94
|
+
end
|
83
95
|
end
|
84
96
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Synvert::Core
|
6
|
+
describe Rewriter::RubyVersion do
|
7
|
+
it 'returns true if ruby version is greater than 1.9' do
|
8
|
+
ruby_version = Rewriter::RubyVersion.new('1.9')
|
9
|
+
expect(ruby_version).to be_match
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false if ruby version is less than 19.0' do
|
13
|
+
ruby_version = Rewriter::RubyVersion.new('19.0')
|
14
|
+
expect(ruby_version).not_to be_match
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -230,6 +230,12 @@ module Synvert::Core
|
|
230
230
|
Rewriter.call 'group', 'rewriter'
|
231
231
|
end
|
232
232
|
|
233
|
+
it 'registers and calls rewriter in sandbox mode' do
|
234
|
+
rewriter = Rewriter.new 'group', 'rewriter'
|
235
|
+
expect(rewriter).to receive(:process_with_sandbox)
|
236
|
+
Rewriter.call 'group', 'rewriter', true
|
237
|
+
end
|
238
|
+
|
233
239
|
it 'raises RewriterNotFound if rewriter not found' do
|
234
240
|
expect { Rewriter.call 'group', 'rewriter' }.to raise_error(RewriterNotFound)
|
235
241
|
end
|
data/synvert-core.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'synvert/core/version'
|
5
6
|
|
@@ -8,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.version = Synvert::Core::VERSION
|
9
10
|
spec.authors = ["Richard Huang"]
|
10
11
|
spec.email = ["flyerhzm@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
12
|
+
spec.summary = 'convert ruby code to better syntax.'
|
13
|
+
spec.description = 'convert ruby code to better syntax automatically.'
|
13
14
|
spec.homepage = "https://github.com/xinminlabs/synvert-core"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
@@ -18,13 +19,13 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
|
-
spec.add_runtime_dependency "parser", "~> 3.0.0"
|
22
22
|
spec.add_runtime_dependency "activesupport"
|
23
23
|
spec.add_runtime_dependency "erubis"
|
24
|
+
spec.add_runtime_dependency "parser", "~> 3.0.0"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec"
|
28
27
|
spec.add_development_dependency "guard"
|
29
28
|
spec.add_development_dependency "guard-rspec"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rspec"
|
30
31
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.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-02-
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
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
|
-
name:
|
28
|
+
name: erubis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: parser
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: guard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
84
|
+
name: guard-rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -167,7 +167,6 @@ files:
|
|
167
167
|
- lib/synvert/core/version.rb
|
168
168
|
- spec/spec_helper.rb
|
169
169
|
- spec/support/parser_helper.rb
|
170
|
-
- spec/synvert/core/configuration_spec.rb
|
171
170
|
- spec/synvert/core/engine/erb_spec.rb
|
172
171
|
- spec/synvert/core/node_ext_spec.rb
|
173
172
|
- spec/synvert/core/rewriter/action/append_action_spec.rb
|
@@ -184,6 +183,7 @@ files:
|
|
184
183
|
- spec/synvert/core/rewriter/gem_spec_spec.rb
|
185
184
|
- spec/synvert/core/rewriter/helper_spec.rb
|
186
185
|
- spec/synvert/core/rewriter/instance_spec.rb
|
186
|
+
- spec/synvert/core/rewriter/ruby_version_spec.rb
|
187
187
|
- spec/synvert/core/rewriter/scope/goto_scope_spec.rb
|
188
188
|
- spec/synvert/core/rewriter/scope/within_scope.rb
|
189
189
|
- spec/synvert/core/rewriter/scope_spec.rb
|
@@ -216,7 +216,6 @@ summary: convert ruby code to better syntax.
|
|
216
216
|
test_files:
|
217
217
|
- spec/spec_helper.rb
|
218
218
|
- spec/support/parser_helper.rb
|
219
|
-
- spec/synvert/core/configuration_spec.rb
|
220
219
|
- spec/synvert/core/engine/erb_spec.rb
|
221
220
|
- spec/synvert/core/node_ext_spec.rb
|
222
221
|
- spec/synvert/core/rewriter/action/append_action_spec.rb
|
@@ -233,6 +232,7 @@ test_files:
|
|
233
232
|
- spec/synvert/core/rewriter/gem_spec_spec.rb
|
234
233
|
- spec/synvert/core/rewriter/helper_spec.rb
|
235
234
|
- spec/synvert/core/rewriter/instance_spec.rb
|
235
|
+
- spec/synvert/core/rewriter/ruby_version_spec.rb
|
236
236
|
- spec/synvert/core/rewriter/scope/goto_scope_spec.rb
|
237
237
|
- spec/synvert/core/rewriter/scope/within_scope.rb
|
238
238
|
- spec/synvert/core/rewriter/scope_spec.rb
|