synvert 1.1.0 → 1.1.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: ab295abb4db951a0f0503a8de8b08a3a4ab63a94aebee8013022b9e162008fda
4
- data.tar.gz: 9405de0a2fb2e50eff97377d2781922d0c8799d23e039b42b26bb858efaa8e11
3
+ metadata.gz: fca31952aad5373170fb41622c3dc07c11aa605ae8d13fb8770229062f9543b8
4
+ data.tar.gz: b57362eedac41f759e397dd10cfb0641690844161ae36e26c5cfd4fbd926d70a
5
5
  SHA512:
6
- metadata.gz: 11f76d1eca1d2f997b7627fc764c9273a0d6c407614c87193d6e29a9130979413779db59d371d46a07c0fcbb619f0ca35340e456a0e20606d91876a5bfa63700
7
- data.tar.gz: d1946063321f8dac68689ef96f0ce4ebef5ebe607c4cadd2440a2955eac8cc02c8ff6c23a5f5a563402a69f46fa003d184f40296faf7d9e53d7d256fa64044e8
6
+ metadata.gz: c7e6e5fe021673fd412a984595258134633d2b5d4612e6e9633568865b3e676d662b597024ab3d7cfcc2d285a8586736a0ca76db33d61c401fe62d7677c48b7c
7
+ data.tar.gz: 60f4d25764698275cb360ef222e07e3794e4bf33f0cde79fb73c87982f43df8516330b3552a3e6d331d77d773e3777ff62854c6c376054557ac2356717391b78
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.1 (2022-10-05)
4
+
5
+ * Fix get_last_snippet_name, eval snippet to get rewriter
6
+
3
7
  ## 1.1.0 (2022-10-03))
4
8
 
5
9
  * Fix sub snippet not found
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert (1.1.0)
4
+ synvert (1.1.1)
5
5
  synvert-core (>= 1.9.2)
6
6
 
7
7
  GEM
data/lib/synvert/cli.rb CHANGED
@@ -47,12 +47,12 @@ module Synvert
47
47
  execute_snippet(@options[:execute_command])
48
48
  when 'test'
49
49
  read_rewriters
50
- group, name = get_snippet_name(@options[:snippet_name])
51
- test_snippet(group, name)
50
+ rewriter = eval_snippet(@options[:snippet_name])
51
+ test_snippet(rewriter)
52
52
  when 'run'
53
53
  read_rewriters
54
- group, name = get_snippet_name(@options[:snippet_name])
55
- run_snippet(group, name)
54
+ rewriter = eval_snippet(@options[:snippet_name])
55
+ run_snippet(rewriter)
56
56
  else
57
57
  # nothing to do
58
58
  end
@@ -233,41 +233,38 @@ module Synvert
233
233
  end
234
234
  end
235
235
 
236
- # get snippet name
237
- # it can get from explicit snippet name,
236
+ # eval snippet by name
237
+ # it can eval by explicit snippet name,
238
238
  # or from local path or http url.
239
- def get_snippet_name(snippet_name)
239
+ def eval_snippet(snippet_name)
240
240
  if /^http/.match?(snippet_name)
241
241
  uri = URI.parse(snippet_name)
242
242
  eval(uri.open.read)
243
- get_last_snippet_name
244
243
  elsif File.exists?(snippet_name)
245
- require(snippet_name)
246
- get_last_snippet_name
244
+ eval(File.read(snippet_name))
247
245
  else
248
246
  require(File.join(default_snippets_home, 'lib', "#{snippet_name}.rb"))
249
- snippet_name.split('/')
247
+ group, name = snippet_name.split('/')
248
+ Core::Rewriter.fetch(group, name)
250
249
  end
251
250
  end
252
251
 
253
- # get snippet name by user inputs
254
- def get_snippet_name_by_input(input)
255
- rewriter = eval(input)
256
- get_last_snippet_name
252
+ # eval snippet name by user input
253
+ def eval_snippet_name_by_input(input)
254
+ eval(input)
257
255
  end
258
256
 
259
257
  # run a snippet
260
- def run_snippet(group, name)
258
+ def run_snippet(rewriter)
259
+ rewriter.process
261
260
  if plain_output?
262
- puts "===== #{group}/#{name} started ====="
263
- rewriter = Core::Rewriter.call group, name
261
+ puts "===== #{rewriter.group}/#{rewriter.name} started ====="
264
262
  rewriter.warnings.each do |warning|
265
263
  puts '[Warn] ' + warning.message
266
264
  end
267
265
  puts rewriter.todo if rewriter.todo
268
- puts "===== #{group}/#{name} done ====="
266
+ puts "===== #{rewriter.group}/#{rewriter.name} done ====="
269
267
  elsif json_output?
270
- rewriter = Core::Rewriter.call group, name
271
268
  output = {
272
269
  affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum(Set.new, &:affected_files)).to_a,
273
270
  warnings: rewriter.warnings.union(rewriter.sub_snippets.sum([], &:warnings)),
@@ -278,8 +275,7 @@ module Synvert
278
275
  end
279
276
 
280
277
  # test a snippet
281
- def test_snippet(group, name)
282
- rewriter = Core::Rewriter.fetch(group, name)
278
+ def test_snippet(rewriter)
283
279
  results = rewriter.test
284
280
  rewriter.sub_snippets.each do |sub_snippet|
285
281
  results += sub_snippet.test_results
@@ -289,11 +285,11 @@ module Synvert
289
285
 
290
286
  # execute snippet
291
287
  def execute_snippet(execute_command)
292
- group, name = get_snippet_name_by_input(STDIN.read)
288
+ rewriter = eval_snippet_name_by_input(STDIN.read)
293
289
  if execute_command == 'test'
294
- test_snippet(group, name)
290
+ test_snippet(rewriter)
295
291
  else
296
- run_snippet(group, name)
292
+ run_snippet(rewriter)
297
293
  end
298
294
  end
299
295
 
@@ -356,12 +352,5 @@ module Synvert
356
352
  def json_output?
357
353
  @options[:format] == 'json'
358
354
  end
359
-
360
- # get the last registered snippet name
361
- def get_last_snippet_name
362
- group = Rewriter.availables.keys.last
363
- name = Rewriter.availables[group].keys.last
364
- return group, name
365
- end
366
355
  end
367
356
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Synvert
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.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: 2022-10-03 00:00:00.000000000 Z
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: synvert-core
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.3.7
129
+ rubygems_version: 3.3.22
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: synvert = syntax + convert.