synvert 0.9.0 → 0.10.0

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
- SHA1:
3
- metadata.gz: 8941e003bae93eb24a188ff2dbcb48dbad8cc2b6
4
- data.tar.gz: e796edccc2f96ff9ea1f3303c51360ffdbdf90a3
2
+ SHA256:
3
+ metadata.gz: 430688d602830d6cbccecf277a580969288b875e992dc1447eb108a7ebd0726c
4
+ data.tar.gz: 6ea78cce8187cea7470bbc043978b318a4f0bd608bf13124cb9ec5f75917fe37
5
5
  SHA512:
6
- metadata.gz: 77e919724aa7ec0508621a38a7a5cea5d85ec05925bf8b0bdacb9e6509cb5ce5593ebc5b96110d90d771d7ef936891e5a6c48de8303e427602d7d11ff350da32
7
- data.tar.gz: 7ec460303474e7f5116983c6e6097cb9338e9f8c40eb93dad50d9978e0a1fa1beda9cd86fa6937588a99e68d17b3769206ef69b08004a3835d758ec26c334b2a
6
+ metadata.gz: dad3de4c88092bba08138b0b64d70e92fa33ca2d8d4d7acea22d7b5e468e48fb2b08b8531832c985b03f5a4b6c2e0fda5f5aa415aae204c414fc5d14d18646c1
7
+ data.tar.gz: e500c57544648cb230f43e52658d58c36bde8a13f052c5e66441fc3471c43e867c8693a0b4fde23a9a9c6c69eae28c0d174ef5ddedec499ff6594a676b0beece
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
3
+ - 2.1
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
- Try to keep same version to gem `synvert-core`.
3
+ ## 0.10.0 (2021-02-07)
4
+
5
+ * Use new `Core::Confiruation`
6
+ * Use require instead of eval in order to preserve normal Ruby semantics
4
7
 
5
8
  ## 0.9.0
6
9
 
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Synvert
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/xinminlabs/synvert.png)](http://travis-ci.org/xinminlabs/synvert)
4
- [![Coverage Status](https://coveralls.io/repos/xinminlabs/synvert/badge.png?branch=master)](https://coveralls.io/r/xinminlabs/synvert)
5
- [![Gem Version](https://badge.fury.io/rb/synvert.png)](http://badge.fury.io/rb/synvert)
3
+ [![Build Status](https://secure.travis-ci.org/xinminlabs/synvert.svg)](http://travis-ci.org/xinminlabs/synvert)
4
+ [![Coverage Status](https://coveralls.io/repos/xinminlabs/synvert/badge.svg?branch=master)](https://coveralls.io/r/xinminlabs/synvert)
5
+ [![Gem Version](https://badge.fury.io/rb/synvert.svg)](http://badge.fury.io/rb/synvert)
6
6
 
7
7
  Synvert = syntax + convert, makes it easy to convert ruby code
8
8
  automatically.
9
9
 
10
- Synvert is tested against MRI 1.9.3, 2.0.0 and 2.1.1.
10
+ Synvert is tested against MRI 1.9.3, 2.0.0, 2.1.7 and 2.2.3.
11
11
 
12
12
  Synvert is composed by synvert-core and synvert-snippets.
13
13
 
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
data/lib/synvert.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require "synvert/version"
2
+ require 'synvert/version'
3
3
  require 'bundler'
4
4
  require 'synvert/core'
5
5
 
data/lib/synvert/cli.rb CHANGED
@@ -15,8 +15,6 @@ module Synvert
15
15
  # Initialize a CLI.
16
16
  def initialize
17
17
  @options = {command: 'run', custom_snippet_paths: [], snippet_names: []}
18
- Core::Configuration.instance.set :skip_files, []
19
- Core::Configuration.instance.set :default_snippets_path, File.join(ENV['HOME'], '.synvert')
20
18
  end
21
19
 
22
20
  # Run the CLI.
@@ -39,14 +37,14 @@ module Synvert
39
37
  show_rewriter
40
38
  when 'sync'
41
39
  sync_snippets
42
- else
40
+ else # run
43
41
  load_rewriters
44
42
  @options[:snippet_names].each do |snippet_name|
45
43
  puts "===== #{snippet_name} started ====="
46
44
  group, name = snippet_name.split('/')
47
45
  rewriter = Core::Rewriter.call group, name
48
46
  rewriter.warnings.each do |warning|
49
- puts "[Warn] " + warning.message
47
+ puts '[Warn] ' + warning.message
50
48
  end
51
49
  puts rewriter.todo if rewriter.todo
52
50
  puts "===== #{snippet_name} done ====="
@@ -70,7 +68,7 @@ module Synvert
70
68
  # Run OptionParser to parse arguments.
71
69
  def run_option_parser(args)
72
70
  optparse = OptionParser.new do |opts|
73
- opts.banner = "Usage: synvert [project_path]"
71
+ opts.banner = 'Usage: synvert [project_path]'
74
72
  opts.on '-d', '--load SNIPPET_PATHS', 'load custom snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
75
73
  @options[:custom_snippet_paths] = snippet_paths.split(',').map(&:strip)
76
74
  end
@@ -104,26 +102,26 @@ module Synvert
104
102
  end
105
103
  end
106
104
  paths = optparse.parse(args)
107
- Core::Configuration.instance.set :path, paths.first || Dir.pwd
105
+ Core::Configuration.path = paths.first || Dir.pwd
108
106
  if @options[:skip_file_patterns] && !@options[:skip_file_patterns].empty?
109
- skip_files = @options[:skip_file_patterns].map { |file_pattern|
110
- full_file_pattern = File.join(Core::Configuration.instance.get(:path), file_pattern)
107
+ skip_files = @options[:skip_file_patterns].map do |file_pattern|
108
+ full_file_pattern = File.join(Core::Configuration.path, file_pattern)
111
109
  Dir.glob(full_file_pattern)
112
- }.flatten
113
- Core::Configuration.instance.set :skip_files, skip_files
110
+ end.flatten
111
+ Core::Configuration.skip_files = skip_files
114
112
  end
115
113
  end
116
114
 
117
115
  # Load all rewriters.
118
116
  def load_rewriters
119
- Dir.glob(File.join(default_snippets_path, 'lib/**/*.rb')).each { |file| eval(File.read(file)) }
117
+ Dir.glob(File.join(default_snippets_path, 'lib/**/*.rb')).each { |file| require file }
120
118
 
121
119
  @options[:custom_snippet_paths].each do |snippet_path|
122
120
  if snippet_path =~ /^http/
123
121
  uri = URI.parse snippet_path
124
122
  eval(uri.read)
125
123
  else
126
- eval(File.read(snippet_path))
124
+ require snippet_path
127
125
  end
128
126
  end
129
127
  rescue
@@ -134,12 +132,12 @@ module Synvert
134
132
  # List and print all available rewriters.
135
133
  def list_available_rewriters
136
134
  if Core::Rewriter.availables.empty?
137
- puts "There is no snippet under ~/.synvert, please run `synvert --sync` to fetch snippets."
135
+ puts 'There is no snippet under ~/.synvert, please run `synvert --sync` to fetch snippets.'
138
136
  else
139
137
  Core::Rewriter.availables.each do |group, rewriters|
140
138
  puts group
141
139
  rewriters.each do |name, rewriter|
142
- puts " " + name
140
+ puts ' ' + name
143
141
  end
144
142
  end
145
143
  puts
@@ -149,7 +147,7 @@ module Synvert
149
147
  # Open one rewriter.
150
148
  def open_rewriter
151
149
  editor = [ENV['SYNVERT_EDITOR'], ENV['EDITOR']].find { |e| !e.nil? && !e.empty? }
152
- return puts "To open a synvert snippet, set $EDITOR or $SYNVERT_EDITOR" unless editor
150
+ return puts 'To open a synvert snippet, set $EDITOR or $SYNVERT_EDITOR' unless editor
153
151
 
154
152
  path = File.expand_path(File.join(default_snippets_path, "lib/#{@options[:snippet_name]}.rb"))
155
153
  if File.exist? path
@@ -165,12 +163,12 @@ module Synvert
165
163
  if group.include? @options[:query]
166
164
  puts group
167
165
  rewriters.each do |name, rewriter|
168
- puts " " + name
166
+ puts ' ' + name
169
167
  end
170
168
  elsif rewriters.keys.any? { |name| name.include? @options[:query] }
171
169
  puts group
172
170
  rewriters.each do |name, rewriter|
173
- puts " " + name if name.include?(@options[:query])
171
+ puts ' ' + name if name.include?(@options[:query])
174
172
  end
175
173
  end
176
174
  end
@@ -186,9 +184,9 @@ module Synvert
186
184
  puts rewriter.description
187
185
  rewriter.sub_snippets.each do |sub_rewriter|
188
186
  puts
189
- puts "=" * 80
187
+ puts '=' * 80
190
188
  puts "snippet: #{sub_rewriter.name}"
191
- puts "=" * 80
189
+ puts '=' * 80
192
190
  puts sub_rewriter.description
193
191
  end
194
192
  else
@@ -198,8 +196,8 @@ module Synvert
198
196
 
199
197
  # sync snippets
200
198
  def sync_snippets
201
- Snippet.sync
202
- puts "synvert snippets are synced"
199
+ Snippet.new(default_snippets_path).sync
200
+ puts 'synvert snippets are synced'
203
201
  core_version = Snippet.fetch_core_version
204
202
  if Gem::Version.new(core_version) > Gem::Version.new(Synvert::Core::VERSION)
205
203
  puts "synvert-core is updated, please install synvert-core #{core_version}"
@@ -207,7 +205,7 @@ module Synvert
207
205
  end
208
206
 
209
207
  def default_snippets_path
210
- Core::Configuration.instance.get :default_snippets_path
208
+ File.join(ENV['HOME'], '.synvert')
211
209
  end
212
210
  end
213
211
  end
@@ -5,20 +5,23 @@ require 'json'
5
5
  module Synvert
6
6
  # Manage synvert snippets.
7
7
  class Snippet
8
+ def initialize(snippets_path)
9
+ @snippets_path = snippets_path
10
+ end
11
+
8
12
  # synchronize snippets from github.
9
- def self.sync
10
- snippets_path = Core::Configuration.instance.get :default_snippets_path
11
- if File.exist?(snippets_path)
12
- FileUtils.cd snippets_path
13
- system("git pull --rebase")
13
+ def sync
14
+ if File.exist?(@snippets_path)
15
+ FileUtils.cd @snippets_path
16
+ Kernel.system('git pull --rebase')
14
17
  else
15
- system("git clone https://github.com/xinminlabs/synvert-snippets.git #{snippets_path}")
18
+ Kernel.system("git clone https://github.com/xinminlabs/synvert-snippets.git #{@snippets_path}")
16
19
  end
17
20
  end
18
21
 
19
- def self.fetch_core_version
20
- content = open("https://rubygems.org/api/v1/versions/synvert-core.json").read
21
- JSON.parse(content).first["number"]
22
+ def fetch_core_version
23
+ content = URI.open('https://rubygems.org/api/v1/versions/synvert-core.json').read
24
+ JSON.parse(content).first['number']
22
25
  end
23
26
  end
24
27
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.9.0"
4
+ VERSION = '0.10.0'
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
 
3
3
  require 'synvert'
4
4
  require 'webmock/rspec'
@@ -2,28 +2,29 @@ require 'spec_helper'
2
2
 
3
3
  module Synvert
4
4
  describe Snippet do
5
- describe "sync" do
6
- let(:default_snippets_path) { File.join(File.dirname(__FILE__), '.synvert') }
7
- before { Core::Configuration.instance.set :default_snippets_path, default_snippets_path }
8
- after { FileUtils.rm_rf default_snippets_path }
5
+ let(:snippets_path) { File.join(File.dirname(__FILE__), '.synvert') }
6
+ let(:snippet) { Snippet.new(snippets_path) }
7
+ after { FileUtils.rmdir(snippets_path) if File.exist?(snippets_path) }
9
8
 
9
+ describe 'sync' do
10
10
  it 'git clones snippets' do
11
- expect(Snippet).to receive(:system).with("git clone https://github.com/xinminlabs/synvert-snippets.git #{default_snippets_path}")
12
- Snippet.sync
11
+ expect(Kernel).to receive(:system).with("git clone https://github.com/xinminlabs/synvert-snippets.git #{snippets_path}")
12
+ snippet.sync
13
13
  end
14
14
 
15
15
  it 'git pull snippets' do
16
- FileUtils.mkdir default_snippets_path
17
- expect(Snippet).to receive(:system).with("git pull --rebase")
18
- Snippet.sync
16
+ FileUtils.mkdir snippets_path
17
+ expect(Kernel).to receive(:system).with('git pull --rebase')
18
+ snippet.sync
19
+ FileUtils.cd File.dirname(__FILE__)
19
20
  end
20
21
  end
21
22
 
22
- describe "fetch_core_version" do
23
+ describe 'fetch_core_version' do
23
24
  it 'gets remote version' do
24
- stub_request(:get, "https://rubygems.org/api/v1/versions/synvert-core.json").
25
+ stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').
25
26
  to_return(:body => '[{"number":"0.4.2"}]')
26
- expect(Snippet.fetch_core_version).to eq "0.4.2"
27
+ expect(snippet.fetch_core_version).to eq '0.4.2'
27
28
  end
28
29
  end
29
30
  end
data/synvert.gemspec CHANGED
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'synvert/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "synvert"
7
+ spec.name = 'synvert'
8
8
  spec.version = Synvert::VERSION
9
- spec.authors = ["Richard Huang"]
10
- spec.email = ["flyerhzm@gmail.com"]
11
- spec.description = %q{synvert is used to convert ruby code to better syntax.}
12
- spec.summary = %q{synvert = syntax + convert.}
13
- spec.homepage = "https://github.com/xinminlabs/synvert"
14
- spec.license = "MIT"
9
+ spec.authors = ['Richard Huang']
10
+ spec.email = ['flyerhzm@gmail.com']
11
+ spec.description = 'synvert is used to convert ruby code to better syntax.'
12
+ spec.summary = 'synvert = syntax + convert.'
13
+ spec.homepage = 'https://github.com/xinminlabs/synvert'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency "synvert-core", ">= 0.5.3"
21
+ spec.add_runtime_dependency 'synvert-core', '>= 0.19.0'
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "webmock"
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'webmock'
27
27
  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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2021-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: synvert-core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.3
19
+ version: 0.19.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: 0.5.3
26
+ version: 0.19.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ homepage: https://github.com/xinminlabs/synvert
108
108
  licenses:
109
109
  - MIT
110
110
  metadata: {}
111
- post_install_message:
111
+ post_install_message:
112
112
  rdoc_options: []
113
113
  require_paths:
114
114
  - lib
@@ -123,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.4.5.1
128
- signing_key:
126
+ rubygems_version: 3.1.4
127
+ signing_key:
129
128
  specification_version: 4
130
129
  summary: synvert = syntax + convert.
131
130
  test_files: