synvert 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/synvert/cli.rb +57 -1
- data/lib/synvert/version.rb +1 -1
- data/spec/synvert/snippet_spec.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1c67ec2f25a9e357beea399dbdf83f6d4a46a2e3a3729843e2cca128a662b73
|
4
|
+
data.tar.gz: 4327ecc60f5d4681c2f03bd6e63c2e854a3f9f278c363a71ef9a48126d82320b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce66beb043128746d3771c38a13887e5bd560246c925c5a1570180878b6b86694a4c83074cb5982adfc21f9a930b13b63434d551050270f92f27e485c3500ac5
|
7
|
+
data.tar.gz: 0550f8223f2f21f4639e5c63dc475767a281c710b06291c69783f68a22441cfb0d8f92f068c22d24d436521cab40c5bcc90d9836b951b3e0e27835be45443561
|
data/CHANGELOG.md
CHANGED
data/lib/synvert/cli.rb
CHANGED
@@ -41,6 +41,8 @@ module Synvert
|
|
41
41
|
show_rewriter
|
42
42
|
when 'sync'
|
43
43
|
sync_snippets
|
44
|
+
when 'generate'
|
45
|
+
generate_snippet
|
44
46
|
else
|
45
47
|
# run
|
46
48
|
load_rewriters
|
@@ -112,8 +114,14 @@ module Synvert
|
|
112
114
|
'run specified snippets, each SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax,ruby/new_lambda_syntax' do |snippet_names|
|
113
115
|
@options[:snippet_names] = snippet_names.split(',').map(&:strip)
|
114
116
|
end
|
117
|
+
opts.on '-g',
|
118
|
+
'--generate NEW_SNIPPET_NAME',
|
119
|
+
'generate a new snippet' do |name|
|
120
|
+
@options[:command] = 'generate'
|
121
|
+
@options[:snippet_name] = name
|
122
|
+
end
|
115
123
|
opts.on '-v', '--version', 'show this version' do
|
116
|
-
puts VERSION
|
124
|
+
puts "#{VERSION} (with synvert-core #{Core::VERSION} and parser #{Parser::VERSION})"
|
117
125
|
exit
|
118
126
|
end
|
119
127
|
end
|
@@ -243,6 +251,54 @@ module Synvert
|
|
243
251
|
end
|
244
252
|
end
|
245
253
|
|
254
|
+
# generate a new snippet
|
255
|
+
def generate_snippet
|
256
|
+
group, name = @options[:snippet_name].split('/')
|
257
|
+
FileUtils.mkdir_p("lib/#{group}")
|
258
|
+
FileUtils.mkdir_p("spec/#{group}")
|
259
|
+
lib_content = <<~EOF
|
260
|
+
# frozen_string_literal: true
|
261
|
+
|
262
|
+
Synvert::Rewriter.new '#{group}', '#{name}' do
|
263
|
+
description <<~EOS
|
264
|
+
It convert Foo to Bar
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
Foo
|
268
|
+
```
|
269
|
+
|
270
|
+
=>
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
Bar
|
274
|
+
```
|
275
|
+
EOS
|
276
|
+
|
277
|
+
within_files '**/*.rb' do
|
278
|
+
with_node type: 'const', to_source: 'Foo' do
|
279
|
+
replace_with 'Bar'
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
EOF
|
284
|
+
spec_content = <<~EOF
|
285
|
+
# frozen_string_literal: true
|
286
|
+
|
287
|
+
require 'spec_helper'
|
288
|
+
|
289
|
+
RSpec.describe 'Convert Foo to Bar' do
|
290
|
+
let(:rewriter_name) { '#{group}/#{name}' }
|
291
|
+
let(:fake_file_path) { 'foobar.rb' }
|
292
|
+
let(:test_content) { 'Foo' }
|
293
|
+
let(:test_rewritten_content) { 'Bar' }
|
294
|
+
|
295
|
+
include_examples 'convertable'
|
296
|
+
end
|
297
|
+
EOF
|
298
|
+
File.write("lib/#{group}/#{name}.rb", lib_content)
|
299
|
+
File.write("spec/#{group}/#{name}_spec.rb", spec_content)
|
300
|
+
end
|
301
|
+
|
246
302
|
def default_snippets_path
|
247
303
|
File.join(ENV['HOME'], '.synvert')
|
248
304
|
end
|
data/lib/synvert/version.rb
CHANGED
@@ -8,6 +8,15 @@ module Synvert
|
|
8
8
|
let(:snippet) { Snippet.new(snippets_path) }
|
9
9
|
after { FileUtils.rmdir(snippets_path) if File.exist?(snippets_path) }
|
10
10
|
|
11
|
+
describe '.fetch_core_version' do
|
12
|
+
it 'gets remote version' do
|
13
|
+
stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').to_return(
|
14
|
+
body: '[{"number":"0.4.2"}]'
|
15
|
+
)
|
16
|
+
expect(Snippet.fetch_core_version).to eq '0.4.2'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
describe 'sync' do
|
12
21
|
it 'git clones snippets' do
|
13
22
|
expect(Kernel).to receive(:system).with(
|
@@ -23,14 +32,5 @@ module Synvert
|
|
23
32
|
FileUtils.cd File.dirname(__FILE__)
|
24
33
|
end
|
25
34
|
end
|
26
|
-
|
27
|
-
describe 'fetch_core_version' do
|
28
|
-
it 'gets remote version' do
|
29
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').to_return(
|
30
|
-
body: '[{"number":"0.4.2"}]'
|
31
|
-
)
|
32
|
-
expect(snippet.fetch_core_version).to eq '0.4.2'
|
33
|
-
end
|
34
|
-
end
|
35
35
|
end
|
36
36
|
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: 0.
|
4
|
+
version: 0.12.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-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: synvert-core
|