synvert 1.1.1 → 1.1.3

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: fca31952aad5373170fb41622c3dc07c11aa605ae8d13fb8770229062f9543b8
4
- data.tar.gz: b57362eedac41f759e397dd10cfb0641690844161ae36e26c5cfd4fbd926d70a
3
+ metadata.gz: 15c02ce8eccc05ac9bd74acc1c48a41299e7feed9e6f5aa74fbdc76001a4ed24
4
+ data.tar.gz: 9d9ae61df8d41a97652cf35839c76134fc1a8def2bf6ec3c1da09a80ae71b02e
5
5
  SHA512:
6
- metadata.gz: c7e6e5fe021673fd412a984595258134633d2b5d4612e6e9633568865b3e676d662b597024ab3d7cfcc2d285a8586736a0ca76db33d61c401fe62d7677c48b7c
7
- data.tar.gz: 60f4d25764698275cb360ef222e07e3794e4bf33f0cde79fb73c87982f43df8516330b3552a3e6d331d77d773e3777ff62854c6c376054557ac2356717391b78
6
+ metadata.gz: 9c69f27c9cc0a1dccb25c00732aef5ad2fcdfbdf8e43767392a6920a16265403c8e6d7f0b23682d62c0ed378cb88e052df55de14bf78dcdee8c0b27e7d41cfa1
7
+ data.tar.gz: 62ad7f2c78e77ee8d6f68e6820b0efd8cd86af1e219ba99248a7dd28ea9436bd33cdf92a32c56599f1f3b1cf4a3bf432bb5f89ed0d5861ba24592305aae48e5a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.3 (2022-10-09)
4
+
5
+ * No need to read rewriters before run or test a snippet
6
+ * Reuse `Synvert::Core::Utils.eval_snippet`
7
+ * `rewriter.test` already returns all results
8
+
9
+ ## 1.1.2 (2022-10-06)
10
+
11
+ * Convert github url to github raw url
12
+
3
13
  ## 1.1.1 (2022-10-05)
4
14
 
5
15
  * Fix get_last_snippet_name, eval snippet to get rewriter
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert (1.1.1)
5
- synvert-core (>= 1.9.2)
4
+ synvert (1.1.3)
5
+ synvert-core (>= 1.10.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -64,7 +64,7 @@ GEM
64
64
  simplecov-html (~> 0.10.0)
65
65
  simplecov-html (0.10.2)
66
66
  sync (0.5.0)
67
- synvert-core (1.9.2)
67
+ synvert-core (1.10.1)
68
68
  activesupport (< 7.0.0)
69
69
  erubis
70
70
  node_mutation
data/lib/synvert/cli.rb CHANGED
@@ -43,15 +43,12 @@ module Synvert
43
43
  when 'generate'
44
44
  generate_snippet
45
45
  when 'execute'
46
- read_rewriters
47
46
  execute_snippet(@options[:execute_command])
48
47
  when 'test'
49
- read_rewriters
50
- rewriter = eval_snippet(@options[:snippet_name])
48
+ rewriter = Synvert::Core::Utils.eval_snippet(@options[:snippet_name])
51
49
  test_snippet(rewriter)
52
50
  when 'run'
53
- read_rewriters
54
- rewriter = eval_snippet(@options[:snippet_name])
51
+ rewriter = Synvert::Core::Utils.eval_snippet(@options[:snippet_name])
55
52
  run_snippet(rewriter)
56
53
  else
57
54
  # nothing to do
@@ -233,22 +230,6 @@ module Synvert
233
230
  end
234
231
  end
235
232
 
236
- # eval snippet by name
237
- # it can eval by explicit snippet name,
238
- # or from local path or http url.
239
- def eval_snippet(snippet_name)
240
- if /^http/.match?(snippet_name)
241
- uri = URI.parse(snippet_name)
242
- eval(uri.open.read)
243
- elsif File.exists?(snippet_name)
244
- eval(File.read(snippet_name))
245
- else
246
- require(File.join(default_snippets_home, 'lib', "#{snippet_name}.rb"))
247
- group, name = snippet_name.split('/')
248
- Core::Rewriter.fetch(group, name)
249
- end
250
- end
251
-
252
233
  # eval snippet name by user input
253
234
  def eval_snippet_name_by_input(input)
254
235
  eval(input)
@@ -256,15 +237,16 @@ module Synvert
256
237
 
257
238
  # run a snippet
258
239
  def run_snippet(rewriter)
259
- rewriter.process
260
240
  if plain_output?
261
241
  puts "===== #{rewriter.group}/#{rewriter.name} started ====="
242
+ rewriter.process
262
243
  rewriter.warnings.each do |warning|
263
244
  puts '[Warn] ' + warning.message
264
245
  end
265
246
  puts rewriter.todo if rewriter.todo
266
247
  puts "===== #{rewriter.group}/#{rewriter.name} done ====="
267
248
  elsif json_output?
249
+ rewriter.process
268
250
  output = {
269
251
  affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum(Set.new, &:affected_files)).to_a,
270
252
  warnings: rewriter.warnings.union(rewriter.sub_snippets.sum([], &:warnings)),
@@ -277,9 +259,6 @@ module Synvert
277
259
  # test a snippet
278
260
  def test_snippet(rewriter)
279
261
  results = rewriter.test
280
- rewriter.sub_snippets.each do |sub_snippet|
281
- results += sub_snippet.test_results
282
- end
283
262
  puts JSON.generate(results)
284
263
  end
285
264
 
@@ -0,0 +1,18 @@
1
+ module Synvert
2
+ module Utils
3
+ class << self
4
+ def format_url(url)
5
+ convert_to_github_raw_url(url)
6
+ end
7
+
8
+ private
9
+
10
+ def convert_to_github_raw_url(url)
11
+ if url.include?('//github.com/')
12
+ url = url.sub('//github.com/', '//raw.githubusercontent.com/').sub('/blob/', '/')
13
+ end
14
+ url
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Synvert
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.3'
5
5
  end
data/lib/synvert.rb CHANGED
@@ -6,5 +6,6 @@ require 'synvert/core'
6
6
 
7
7
  module Synvert
8
8
  autoload :CLI, 'synvert/cli'
9
+ autoload :Utils, 'synvert/utils'
9
10
  autoload :Snippet, 'synvert/snippet'
10
11
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  module Synvert
6
6
  describe Snippet do
7
- let(:snippets_path) { File.join(File.dirname(__FILE__), '.synvert') }
7
+ let(:snippets_path) { File.join(File.dirname(__FILE__), '.synvert-ruby') }
8
8
  let(:snippet) { Snippet.new(snippets_path) }
9
9
  after { FileUtils.rmdir(snippets_path) if File.exist?(snippets_path) }
10
10
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Synvert
6
+ RSpec.describe Utils do
7
+ describe '.format_url' do
8
+ it 'converts github url to github raw url' do
9
+ url = 'https://github.com/xinminlabs/synvert-snippets-ruby/blob/main/lib/ruby/map_and_flatten_to_flat_map.rb'
10
+ raw_url = 'https://raw.githubusercontent.com/xinminlabs/synvert-snippets-ruby/main/lib/ruby/map_and_flatten_to_flat_map.rb'
11
+ expect(described_class.format_url(url)).to eq raw_url
12
+ end
13
+ end
14
+ end
15
+ end
data/synvert-ruby.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
  spec.post_install_message = 'Please run `synvert-ruby --sync` first to sync snippets remotely.'
22
22
 
23
- spec.add_runtime_dependency 'synvert-core', '>= 1.9.2'
23
+ spec.add_runtime_dependency 'synvert-core', '>= 1.10.1'
24
24
 
25
25
  spec.add_development_dependency 'bundler'
26
26
  spec.add_development_dependency 'rake'
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.1
4
+ version: 1.1.3
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-05 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: synvert-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.2
19
+ version: 1.10.1
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: 1.9.2
26
+ version: 1.10.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -103,9 +103,11 @@ files:
103
103
  - lib/synvert.rb
104
104
  - lib/synvert/cli.rb
105
105
  - lib/synvert/snippet.rb
106
+ - lib/synvert/utils.rb
106
107
  - lib/synvert/version.rb
107
108
  - spec/spec_helper.rb
108
109
  - spec/synvert/snippet_spec.rb
110
+ - spec/synvert/utils_spec.rb
109
111
  - synvert-ruby.gemspec
110
112
  homepage: https://github.com/xinminlabs/synvert-ruby
111
113
  licenses:
@@ -133,3 +135,4 @@ summary: synvert = syntax + convert.
133
135
  test_files:
134
136
  - spec/spec_helper.rb
135
137
  - spec/synvert/snippet_spec.rb
138
+ - spec/synvert/utils_spec.rb