synvert-core 0.20.1 → 0.23.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 +13 -3
- data/lib/synvert/core.rb +1 -0
- data/lib/synvert/core/engine/erb.rb +15 -13
- data/lib/synvert/core/node_ext.rb +23 -25
- data/lib/synvert/core/rewriter.rb +20 -6
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +3 -5
- 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 +1 -1
- data/lib/synvert/core/rewriter/helper.rb +17 -1
- data/lib/synvert/core/rewriter/instance.rb +43 -36
- data/lib/synvert/core/rewriter/scope/goto_scope.rb +2 -2
- data/lib/synvert/core/rewriter/scope/within_scope.rb +9 -1
- data/lib/synvert/core/version.rb +1 -1
- 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/instance_spec.rb +1 -0
- data/synvert-core.gemspec +8 -7
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03fc53b8833a45acfc449689b313108daf0e98c93dfd8e197fc9b3940e68816b
|
4
|
+
data.tar.gz: e9563c1fe7e358c748be50638a37ecfb7d155c8c4f4ed6dbcde1cac29ed74b99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d053963cb0dfb4e92e515d965a7651d35d60d2d929e2dce1f46c8a32fc4a6101414cd8b47f185c0b43a10470a340614c2d6048184fb869c5e9e6b60a2f16ff27
|
7
|
+
data.tar.gz: 24307e135f10127b48403cfae69c89c4d71d112a513a83570ae7fd16c625882437e2efadefbd4b683fae6d9ce990ae0c1b104e7da3dbfe5f52a893e6f025df63
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.23.0 (2021-03-14)
|
4
4
|
|
5
|
-
*
|
6
|
-
|
5
|
+
* Accept a node as goto_node argument
|
6
|
+
|
7
|
+
## 0.22.0 (2021-03-13)
|
8
|
+
|
9
|
+
* Track `affected_files` for rewriter
|
10
|
+
* Fix `find_matching_nodes` for `current_node`
|
11
|
+
|
12
|
+
## 0.21.0 (2021-02-25)
|
13
|
+
|
14
|
+
* Set `env['BUNDLE_GEMFILE']` before parsing `Gemfile.lock`
|
15
|
+
* Add `Rewriter::RubyVersion` test
|
16
|
+
* Add `reject_keys_from_hash` helper method
|
7
17
|
|
8
18
|
## 0.20.0 (2021-02-15)
|
9
19
|
|
data/lib/synvert/core.rb
CHANGED
@@ -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
|
@@ -335,24 +335,22 @@ module Parser::AST
|
|
335
335
|
# @param rules [Hash] rules to match.
|
336
336
|
# @return true if matches.
|
337
337
|
def match?(rules)
|
338
|
-
flat_hash(rules)
|
339
|
-
.
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
expected = expected_value(rules, multi_keys)
|
353
|
-
match_value?(actual, expected)
|
354
|
-
end
|
338
|
+
flat_hash(rules).keys.all? do |multi_keys|
|
339
|
+
case multi_keys.last
|
340
|
+
when :any
|
341
|
+
actual_values = actual_value(self, multi_keys[0...-1])
|
342
|
+
expected = expected_value(rules, multi_keys)
|
343
|
+
actual_values.any? { |actual| match_value?(actual, expected) }
|
344
|
+
when :not
|
345
|
+
actual = actual_value(self, multi_keys[0...-1])
|
346
|
+
expected = expected_value(rules, multi_keys)
|
347
|
+
!match_value?(actual, expected)
|
348
|
+
else
|
349
|
+
actual = actual_value(self, multi_keys)
|
350
|
+
expected = expected_value(rules, multi_keys)
|
351
|
+
match_value?(actual, expected)
|
355
352
|
end
|
353
|
+
end
|
356
354
|
end
|
357
355
|
|
358
356
|
# Get rewritten source code.
|
@@ -364,7 +362,7 @@ module Parser::AST
|
|
364
362
|
# @raise [Synvert::Core::MethodNotSupported] if string in block {{ }} does not support.
|
365
363
|
def rewritten_source(code)
|
366
364
|
code.gsub(/{{(.*?)}}/m) do
|
367
|
-
old_code =
|
365
|
+
old_code = Regexp.last_match(1)
|
368
366
|
if respond_to? old_code.split(/\.|\[/).first
|
369
367
|
evaluated = instance_eval old_code
|
370
368
|
case evaluated
|
@@ -410,20 +408,20 @@ module Parser::AST
|
|
410
408
|
def match_value?(actual, expected)
|
411
409
|
case expected
|
412
410
|
when Symbol
|
413
|
-
if Parser::AST::Node
|
411
|
+
if actual.is_a?(Parser::AST::Node)
|
414
412
|
actual.to_source == ":#{expected}"
|
415
413
|
else
|
416
414
|
actual.to_sym == expected
|
417
415
|
end
|
418
416
|
when String
|
419
|
-
if Parser::AST::Node
|
417
|
+
if actual.is_a?(Parser::AST::Node)
|
420
418
|
actual.to_source == expected || (actual.to_source[0] == ':' && actual.to_source[1..-1] == expected) ||
|
421
419
|
actual.to_source[1...-1] == expected
|
422
420
|
else
|
423
421
|
actual.to_s == expected
|
424
422
|
end
|
425
423
|
when Regexp
|
426
|
-
if Parser::AST::Node
|
424
|
+
if actual.is_a?(Parser::AST::Node)
|
427
425
|
actual.to_source =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
|
428
426
|
else
|
429
427
|
actual.to_s =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
|
@@ -435,7 +433,7 @@ module Parser::AST
|
|
435
433
|
when NilClass
|
436
434
|
actual.nil?
|
437
435
|
when Numeric
|
438
|
-
if Parser::AST::Node
|
436
|
+
if actual.is_a?(Parser::AST::Node)
|
439
437
|
actual.children[0] == expected
|
440
438
|
else
|
441
439
|
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
|
@@ -84,7 +86,8 @@ module Synvert::Core
|
|
84
86
|
# @return [Synvert::Core::Rewriter] the registered rewriter.
|
85
87
|
# @raise [Synvert::Core::RewriterNotFound] if the registered rewriter is not found.
|
86
88
|
def call(group, name, sandbox = false)
|
87
|
-
group
|
89
|
+
group = group.to_s
|
90
|
+
name = name.to_s
|
88
91
|
if exist? group, name
|
89
92
|
rewriter = rewriters[group][name]
|
90
93
|
if sandbox
|
@@ -104,7 +107,8 @@ module Synvert::Core
|
|
104
107
|
# @param name [String] the rewriter name.
|
105
108
|
# @return [Boolean] true if the rewriter exist.
|
106
109
|
def exist?(group, name)
|
107
|
-
group
|
110
|
+
group = group.to_s
|
111
|
+
name = name.to_s
|
108
112
|
if rewriters[group] && rewriters[group][name]
|
109
113
|
true
|
110
114
|
else
|
@@ -141,7 +145,9 @@ module Synvert::Core
|
|
141
145
|
# @return [Array] helper methods.
|
142
146
|
# @!attribute [r] warnings
|
143
147
|
# @return [Array<Synvert::Core::Rewriter::Warning>] warning messages.
|
144
|
-
|
148
|
+
# @!attribute [r] affected_files
|
149
|
+
# @return [Set] affected fileds
|
150
|
+
attr_reader :group, :name, :sub_snippets, :helpers, :warnings, :affected_files
|
145
151
|
|
146
152
|
# Initialize a rewriter.
|
147
153
|
# When a rewriter is initialized, it is also registered.
|
@@ -157,13 +163,14 @@ module Synvert::Core
|
|
157
163
|
@helpers = []
|
158
164
|
@sub_snippets = []
|
159
165
|
@warnings = []
|
166
|
+
@affected_files = Set.new
|
160
167
|
self.class.register(@group, @name, self)
|
161
168
|
end
|
162
169
|
|
163
170
|
# Process the rewriter.
|
164
171
|
# It will call the block.
|
165
172
|
def process
|
166
|
-
instance_eval
|
173
|
+
instance_eval(&@block)
|
167
174
|
end
|
168
175
|
|
169
176
|
# Process rewriter with sandbox mode.
|
@@ -184,6 +191,13 @@ module Synvert::Core
|
|
184
191
|
@warnings << warning
|
185
192
|
end
|
186
193
|
|
194
|
+
# Add an affected file.
|
195
|
+
#
|
196
|
+
# @param file_path [String]
|
197
|
+
def add_affected_file(file_path)
|
198
|
+
@affected_files.add(file_path)
|
199
|
+
end
|
200
|
+
|
187
201
|
#######
|
188
202
|
# DSL #
|
189
203
|
#######
|
@@ -23,11 +23,9 @@ module Synvert::Core
|
|
23
23
|
def rewritten_code
|
24
24
|
if rewritten_source.split("\n").length > 1
|
25
25
|
new_code = []
|
26
|
-
rewritten_source
|
27
|
-
|
28
|
-
|
29
|
-
new_code << (index == 0 || !@options[:autoindent] ? line : indent(@node) + line)
|
30
|
-
}
|
26
|
+
rewritten_source.split("\n").each_with_index { |line, index|
|
27
|
+
new_code << (index == 0 || !@options[:autoindent] ? line : indent(@node) + line)
|
28
|
+
}
|
31
29
|
new_code.join("\n")
|
32
30
|
else
|
33
31
|
rewritten_source
|
@@ -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
|
@@ -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
|
@@ -87,43 +87,41 @@ module Synvert::Core
|
|
87
87
|
# and rewrite source code back to original file.
|
88
88
|
def process
|
89
89
|
file_pattern = File.join(Configuration.path, @file_pattern)
|
90
|
-
Dir
|
91
|
-
.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
puts @current_node.debug_info
|
107
|
-
raise
|
108
|
-
end
|
90
|
+
Dir.glob(file_pattern).each do |file_path|
|
91
|
+
next if Configuration.skip_files.include? file_path
|
92
|
+
|
93
|
+
begin
|
94
|
+
conflict_actions = []
|
95
|
+
source = +self.class.file_source(file_path)
|
96
|
+
ast = self.class.file_ast(file_path)
|
97
|
+
|
98
|
+
@current_file = file_path
|
99
|
+
|
100
|
+
process_with_node ast do
|
101
|
+
begin
|
102
|
+
instance_eval(&@block)
|
103
|
+
rescue NoMethodError
|
104
|
+
puts @current_node.debug_info
|
105
|
+
raise
|
109
106
|
end
|
107
|
+
end
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
@actions = []
|
119
|
-
|
120
|
-
self.class.write_file(file_path, source)
|
109
|
+
if @actions.length > 0
|
110
|
+
@actions.sort_by! { |action| action.send(@options[:sort_by]) }
|
111
|
+
conflict_actions = get_conflict_actions
|
112
|
+
@actions.reverse_each do |action|
|
113
|
+
source[action.begin_pos...action.end_pos] = action.rewritten_code
|
114
|
+
source = remove_code_or_whole_line(source, action.line)
|
121
115
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
116
|
+
@actions = []
|
117
|
+
|
118
|
+
update_file(file_path, source)
|
119
|
+
end
|
120
|
+
rescue Parser::SyntaxError
|
121
|
+
puts "[Warn] file #{file_path} was not parsed correctly."
|
122
|
+
# do nothing, iterate next file
|
123
|
+
end while !conflict_actions.empty?
|
124
|
+
end
|
127
125
|
end
|
128
126
|
|
129
127
|
# Gets current node, it allows to get current node in block code.
|
@@ -312,5 +310,14 @@ module Synvert::Core
|
|
312
310
|
source
|
313
311
|
end
|
314
312
|
end
|
313
|
+
|
314
|
+
# It updates a file with new source code.
|
315
|
+
#
|
316
|
+
# @param file_path [String] the file path
|
317
|
+
# @param source [String] the new source code
|
318
|
+
def update_file(file_path, source)
|
319
|
+
self.class.write_file(file_path, source)
|
320
|
+
@rewriter.add_affected_file(file_path)
|
321
|
+
end
|
315
322
|
end
|
316
323
|
end
|
@@ -19,9 +19,9 @@ module Synvert::Core
|
|
19
19
|
current_node = @instance.current_node
|
20
20
|
return unless current_node
|
21
21
|
|
22
|
-
child_node = current_node.send
|
22
|
+
child_node = @child_node_name.is_a?(Parser::AST::Node) ? @child_node_name : current_node.send(@child_node_name)
|
23
23
|
@instance.process_with_other_node child_node do
|
24
|
-
@instance.instance_eval
|
24
|
+
@instance.instance_eval(&@block)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
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,14 @@ 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
|
+
if current_node.type == :begin
|
46
|
+
current_node.children.each do |child_node|
|
47
|
+
matching_nodes << child_node if child_node.match? @rules
|
48
|
+
end
|
49
|
+
elsif current_node.match? @rules
|
50
|
+
matching_nodes << current_node
|
51
|
+
end
|
44
52
|
else
|
45
53
|
current_node.each do |child_node|
|
46
54
|
matching_nodes << child_node if child_node.match? @rules
|
data/lib/synvert/core/version.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
|
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.23.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: 2021-
|
11
|
+
date: 2021-03-14 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
|
- - ">="
|