synvert-core 1.14.1 → 1.15.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 +9 -1
- data/Gemfile.lock +6 -6
- data/lib/synvert/core/node_ext.rb +1 -1
- data/lib/synvert/core/snippet_not_found_error.rb +4 -0
- data/lib/synvert/core/utils.rb +29 -3
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +1 -0
- data/spec/synvert/core/utils_spec.rb +44 -17
- data/synvert-core-ruby.gemspec +3 -3
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82066eb2fad44d4ca47831672a31195bba96aa07206aa23e449d5c519b94b23d
|
4
|
+
data.tar.gz: 70a8566412fc3cf9004441a07e706c79807820003155b4bafdc03cf4c62042cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b33e55196d7d3e13097e7b101ee693111e5a49ad6d93015eba85886214abb125b5a938908ca0feadef772ef6eecdaa8874fc2d8d6ecff044d5506f685db8bc8d
|
7
|
+
data.tar.gz: aa7f05784e6e8710903c47e6616dac0a18bca66b0f04fc6b7089ff8d47f8c5c6d073bdb45fccb04b25765feed6b28313ea08dd80d166e0283cd931e2d9482229
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.15.0 (2022-11-30)
|
4
|
+
|
5
|
+
* Load snippet from github
|
6
|
+
|
7
|
+
## 1.14.2 (2022-11-19)
|
8
|
+
|
9
|
+
* Specify `node_query`, `node_mutation` and `parser_node_ext` versions
|
10
|
+
|
3
11
|
## 1.14.1 (2022-10-26)
|
4
12
|
|
5
|
-
* Abstract AnyValue to NodeQuery
|
13
|
+
* Abstract `AnyValue` to NodeQuery
|
6
14
|
|
7
15
|
## 1.14.0 (2022-10-25)
|
8
16
|
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.15.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
|
-
node_mutation
|
8
|
-
node_query
|
7
|
+
node_mutation (>= 1.7.1)
|
8
|
+
node_query (>= 1.10.0)
|
9
9
|
parallel
|
10
10
|
parser
|
11
|
-
parser_node_ext
|
11
|
+
parser_node_ext (>= 0.4.1)
|
12
12
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
@@ -59,7 +59,7 @@ GEM
|
|
59
59
|
nenv (~> 0.1)
|
60
60
|
shellany (~> 0.0)
|
61
61
|
parallel (1.22.1)
|
62
|
-
parser (3.1.
|
62
|
+
parser (3.1.3.0)
|
63
63
|
ast (~> 2.4.1)
|
64
64
|
parser_node_ext (0.4.1)
|
65
65
|
parser
|
@@ -87,7 +87,7 @@ GEM
|
|
87
87
|
thor (1.2.1)
|
88
88
|
tzinfo (2.0.5)
|
89
89
|
concurrent-ruby (~> 1.0)
|
90
|
-
zeitwerk (2.6.
|
90
|
+
zeitwerk (2.6.6)
|
91
91
|
|
92
92
|
PLATFORMS
|
93
93
|
ruby
|
@@ -27,7 +27,7 @@ module Parser::AST
|
|
27
27
|
# +type: 'send', receiver: { type: 'send', receiver: { type: 'send', message: 'config' }, message: 'active_record' }, message: 'identity_map='+
|
28
28
|
#
|
29
29
|
# Source Code to Ast Node
|
30
|
-
# {https://
|
30
|
+
# {https://playground.synvert.net/ruby}
|
31
31
|
class Node
|
32
32
|
# Get the file name of node.
|
33
33
|
#
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -1,18 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'net/http'
|
3
4
|
require 'uri'
|
5
|
+
require 'open-uri'
|
4
6
|
|
5
7
|
module Synvert::Core
|
6
8
|
class Utils
|
7
9
|
class << self
|
8
10
|
def eval_snippet(snippet_name)
|
11
|
+
eval(load_snippet(snippet_name))
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_snippet(snippet_name)
|
9
15
|
if is_valid_url?(snippet_name)
|
10
16
|
uri = URI.parse(format_url(snippet_name))
|
11
|
-
|
17
|
+
return uri.open.read if remote_snippet_exists?(uri)
|
18
|
+
raise SnippetNotFoundError.new("#{snippet_name} nout found")
|
12
19
|
elsif is_valid_file?(snippet_name)
|
13
|
-
|
20
|
+
return File.read(snippet_name)
|
14
21
|
else
|
15
|
-
|
22
|
+
snippet_path = snippet_expand_path(snippet_name)
|
23
|
+
return File.read(snippet_path) if File.exist?(snippet_path)
|
24
|
+
snippet_uri = URI.parse(format_url(remote_snippet_url(snippet_name)))
|
25
|
+
return snippet_uri.open.read if remote_snippet_exists?(snippet_uri)
|
26
|
+
raise SnippetNotFoundError.new("#{snippet_name} nout found")
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
@@ -26,10 +37,25 @@ module Synvert::Core
|
|
26
37
|
File.exist?(path)
|
27
38
|
end
|
28
39
|
|
40
|
+
def remote_snippet_exists?(uri)
|
41
|
+
req = Net::HTTP.new(uri.host, uri.port)
|
42
|
+
req.use_ssl = uri.scheme == 'https'
|
43
|
+
res = req.request_head(uri.path)
|
44
|
+
res.code == "200"
|
45
|
+
end
|
46
|
+
|
47
|
+
def snippet_expand_path(snippet_name)
|
48
|
+
File.join(default_snippets_home(), 'lib', "#{snippet_name}.rb")
|
49
|
+
end
|
50
|
+
|
29
51
|
def default_snippets_home
|
30
52
|
ENV['SYNVERT_SNIPPETS_HOME'] || File.join(ENV['HOME'], '.synvert-ruby')
|
31
53
|
end
|
32
54
|
|
55
|
+
def remote_snippet_url(snippet_name)
|
56
|
+
"https://github.com/xinminlabs/synvert-snippets-ruby/blob/main/lib/#{snippet_name}.rb"
|
57
|
+
end
|
58
|
+
|
33
59
|
def format_url(url)
|
34
60
|
convert_to_github_raw_url(url)
|
35
61
|
end
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
@@ -3,27 +3,54 @@ require 'spec_helper'
|
|
3
3
|
module Synvert::Core
|
4
4
|
RSpec.describe Utils do
|
5
5
|
describe '.eval_snippet' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
context "by http url" do
|
7
|
+
it 'evals snippet' do
|
8
|
+
expect(described_class).to receive(:remote_snippet_exists?).with(URI.parse('http://example.com/rewriter.rb')).and_return(true)
|
9
|
+
expect_any_instance_of(URI::HTTP).to receive(:open).and_return(StringIO.new("Rewriter.new 'group', 'name' do\nend"))
|
10
|
+
rewriter = described_class.eval_snippet('http://example.com/rewriter.rb')
|
11
|
+
expect(rewriter.group).to eq 'group'
|
12
|
+
expect(rewriter.name).to eq 'name'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'raises error' do
|
16
|
+
expect(described_class).to receive(:remote_snippet_exists?).and_return(false)
|
17
|
+
expect do
|
18
|
+
described_class.eval_snippet('http://example.com/rewriter.rb')
|
19
|
+
end.to raise_error(SnippetNotFoundError)
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
context 'by file path' do
|
24
|
+
it 'evals snippet' do
|
25
|
+
expect(File).to receive(:exist?).and_return(true)
|
26
|
+
expect(File).to receive(:read).and_return("Rewriter.new 'group', 'name' do\nend")
|
27
|
+
rewriter = described_class.eval_snippet('/home/richard/foo/bar.rb')
|
28
|
+
expect(rewriter.group).to eq 'group'
|
29
|
+
expect(rewriter.name).to eq 'name'
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
33
|
+
context 'by snippet name' do
|
34
|
+
it 'evals snippet as file' do
|
35
|
+
expect(File).to receive(:exist?).with("group/name").and_return(false)
|
36
|
+
expect(described_class).to receive(:default_snippets_home).and_return('/home/richard/.synvert-ruby')
|
37
|
+
expect(File).to receive(:exist?).with("/home/richard/.synvert-ruby/lib/group/name.rb").and_return(true)
|
38
|
+
expect(File).to receive(:read).and_return("Rewriter.new 'group', 'name' do\nend")
|
39
|
+
rewriter = described_class.eval_snippet('group/name')
|
40
|
+
expect(rewriter.group).to eq 'group'
|
41
|
+
expect(rewriter.name).to eq 'name'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'evals snippet as github url' do
|
45
|
+
expect(File).to receive(:exist?).with("group/name").and_return(false)
|
46
|
+
expect(described_class).to receive(:default_snippets_home).and_return('/home/richard/.synvert-ruby')
|
47
|
+
expect(File).to receive(:exist?).with("/home/richard/.synvert-ruby/lib/group/name.rb").and_return(false)
|
48
|
+
expect(described_class).to receive(:remote_snippet_exists?).with(URI.parse("https://raw.githubusercontent.com/xinminlabs/synvert-snippets-ruby/main/lib/group/name.rb")).and_return(true)
|
49
|
+
expect_any_instance_of(URI::HTTP).to receive(:open).and_return(StringIO.new("Rewriter.new 'group', 'name' do\nend"))
|
50
|
+
rewriter = described_class.eval_snippet('group/name')
|
51
|
+
expect(rewriter.group).to eq 'group'
|
52
|
+
expect(rewriter.name).to eq 'name'
|
53
|
+
end
|
27
54
|
end
|
28
55
|
end
|
29
56
|
end
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
23
|
spec.add_runtime_dependency "erubis"
|
24
|
-
spec.add_runtime_dependency "node_query"
|
25
|
-
spec.add_runtime_dependency "node_mutation"
|
24
|
+
spec.add_runtime_dependency "node_query", ">= 1.10.0"
|
25
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.7.1"
|
26
26
|
spec.add_runtime_dependency "parser"
|
27
|
-
spec.add_runtime_dependency "parser_node_ext"
|
27
|
+
spec.add_runtime_dependency "parser_node_ext", ">= 0.4.1"
|
28
28
|
spec.add_runtime_dependency "parallel"
|
29
29
|
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: 1.
|
4
|
+
version: 1.15.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: 2022-
|
11
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.10.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: 1.10.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: node_mutation
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.7.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.7.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: parser
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.4.1
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.4.1
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: parallel
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/synvert/core/rewriter/scope/goto_scope.rb
|
146
146
|
- lib/synvert/core/rewriter/scope/within_scope.rb
|
147
147
|
- lib/synvert/core/rewriter/warning.rb
|
148
|
+
- lib/synvert/core/snippet_not_found_error.rb
|
148
149
|
- lib/synvert/core/strategy.rb
|
149
150
|
- lib/synvert/core/utils.rb
|
150
151
|
- lib/synvert/core/version.rb
|
@@ -187,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
188
|
- !ruby/object:Gem::Version
|
188
189
|
version: '0'
|
189
190
|
requirements: []
|
190
|
-
rubygems_version: 3.3.
|
191
|
+
rubygems_version: 3.3.26
|
191
192
|
signing_key:
|
192
193
|
specification_version: 4
|
193
194
|
summary: convert ruby code to better syntax.
|