synvert-core 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -0
- data/Rakefile +4 -0
- data/lib/synvert/core/rewriter.rb +1 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/configuration_spec.rb +10 -0
- data/spec/synvert/core/rewriter_spec.rb +10 -4
- metadata +3 -2
- data/lib/synvert/core/cli.rb +0 -147
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 060a67494f8695693b472fe25ed39d9af6021a28
|
4
|
+
data.tar.gz: 67485c8861388275535bd8e3a0ab775ae558220d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2e3ecbb02ee560b8fed9c0a968bfbc35d2eea5598a94147bbab9a26895813e6de414a94375cbfd5e24987dbe9960f87a1518b7a957e2cbf660a25fe55f16fff
|
7
|
+
data.tar.gz: e0926950d6b9b55c3ab138a095706dcdbf99cbc92a2789e33db9c83e47c2a8026b4adccd07c6bb2a1c55aebea9ad9ceedce542cd023b993cb05ef1b01882c10a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/synvert/core/version.rb
CHANGED
@@ -143,10 +143,16 @@ module Synvert::Core
|
|
143
143
|
Rewriter.call 'rewriter'
|
144
144
|
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
146
|
+
context "available" do
|
147
|
+
it 'lists empty rewriters' do
|
148
|
+
expect(Rewriter.availables).to eq []
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'registers and lists all available rewriters' do
|
152
|
+
rewriter1 = Rewriter.new 'rewriter1'
|
153
|
+
rewriter2 = Rewriter.new 'rewriter2'
|
154
|
+
expect(Rewriter.availables).to eq [rewriter1, rewriter2]
|
155
|
+
end
|
150
156
|
end
|
151
157
|
end
|
152
158
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -96,7 +96,6 @@ files:
|
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
98
|
- lib/synvert/core.rb
|
99
|
-
- lib/synvert/core/cli.rb
|
100
99
|
- lib/synvert/core/configuration.rb
|
101
100
|
- lib/synvert/core/exceptions.rb
|
102
101
|
- lib/synvert/core/node_ext.rb
|
@@ -109,6 +108,7 @@ files:
|
|
109
108
|
- lib/synvert/core/version.rb
|
110
109
|
- spec/spec_helper.rb
|
111
110
|
- spec/support/parser_helper.rb
|
111
|
+
- spec/synvert/core/configuration_spec.rb
|
112
112
|
- spec/synvert/core/node_ext_spec.rb
|
113
113
|
- spec/synvert/core/rewriter/action_spec.rb
|
114
114
|
- spec/synvert/core/rewriter/condition_spec.rb
|
@@ -144,6 +144,7 @@ summary: convert ruby code to better syntax.
|
|
144
144
|
test_files:
|
145
145
|
- spec/spec_helper.rb
|
146
146
|
- spec/support/parser_helper.rb
|
147
|
+
- spec/synvert/core/configuration_spec.rb
|
147
148
|
- spec/synvert/core/node_ext_spec.rb
|
148
149
|
- spec/synvert/core/rewriter/action_spec.rb
|
149
150
|
- spec/synvert/core/rewriter/condition_spec.rb
|
data/lib/synvert/core/cli.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'optparse'
|
3
|
-
require 'open-uri'
|
4
|
-
|
5
|
-
module Synvert::Core
|
6
|
-
# Synvert command line interface.
|
7
|
-
class CLI
|
8
|
-
# Initialize the cli and run.
|
9
|
-
#
|
10
|
-
# @param args [Array] arguments, default is ARGV.
|
11
|
-
# @return [Boolean] true if command runs successfully.
|
12
|
-
def self.run(args = ARGV)
|
13
|
-
new.run(args)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Initialize a CLI.
|
17
|
-
def initialize
|
18
|
-
@options = {command: 'run', snippet_paths: [], snippet_names: []}
|
19
|
-
Configuration.instance.set :skip_files, []
|
20
|
-
end
|
21
|
-
|
22
|
-
# Run the CLI.
|
23
|
-
# @param args [Array] arguments.
|
24
|
-
# @return [Boolean] true if command runs successfully.
|
25
|
-
def run(args)
|
26
|
-
run_option_parser(args)
|
27
|
-
load_rewriters
|
28
|
-
|
29
|
-
case @options[:command]
|
30
|
-
when 'list' then list_available_rewriters
|
31
|
-
when 'query' then query_available_rewriters
|
32
|
-
when 'show' then show_rewriter
|
33
|
-
else
|
34
|
-
@options[:snippet_names].each do |snippet_name|
|
35
|
-
puts "===== #{snippet_name} started ====="
|
36
|
-
rewriter = Rewriter.call snippet_name
|
37
|
-
puts rewriter.todo if rewriter.todo
|
38
|
-
puts "===== #{snippet_name} done ====="
|
39
|
-
end
|
40
|
-
end
|
41
|
-
true
|
42
|
-
rescue SystemExit
|
43
|
-
true
|
44
|
-
rescue Parser::SyntaxError => e
|
45
|
-
puts "Syntax error: #{e.message}"
|
46
|
-
puts "file #{e.diagnostic.location.source_buffer.name}"
|
47
|
-
puts "line #{e.diagnostic.location.line}"
|
48
|
-
false
|
49
|
-
rescue Exception => e
|
50
|
-
print "Error: "
|
51
|
-
p e
|
52
|
-
false
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
# Run OptionParser to parse arguments.
|
58
|
-
def run_option_parser(args)
|
59
|
-
optparse = OptionParser.new do |opts|
|
60
|
-
opts.banner = "Usage: synvert [project_path]"
|
61
|
-
opts.on '-d', '--load SNIPPET_PATHS', 'load additional snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
|
62
|
-
@options[:snippet_paths] = snippet_paths.split(',').map(&:strip)
|
63
|
-
end
|
64
|
-
opts.on '-l', '--list', 'list all available snippets' do
|
65
|
-
@options[:command] = 'list'
|
66
|
-
end
|
67
|
-
opts.on '-q', '--query QUERY', 'query specified snippets' do |query|
|
68
|
-
@options[:command] = 'query'
|
69
|
-
@options[:query] = query
|
70
|
-
end
|
71
|
-
opts.on '--skip FILE_PATTERNS', 'skip specified files or directories, separated by comma, e.g. app/models/post.rb,vendor/plugins/**/*.rb' do |file_patterns|
|
72
|
-
@options[:skip_file_patterns] = file_patterns.split(',')
|
73
|
-
end
|
74
|
-
opts.on '-s', '--show SNIPPET_NAME', 'show specified snippet description' do |snippet_name|
|
75
|
-
@options[:command] = 'show'
|
76
|
-
@options[:snippet_name] = snippet_name
|
77
|
-
end
|
78
|
-
opts.on '-r', '--run SNIPPET_NAMES', 'run specified snippets' do |snippet_names|
|
79
|
-
@options[:snippet_names] = snippet_names.split(',').map(&:strip)
|
80
|
-
end
|
81
|
-
opts.on '-v', '--version', 'show this version' do
|
82
|
-
puts Synvert::Core::VERSION
|
83
|
-
exit
|
84
|
-
end
|
85
|
-
end
|
86
|
-
paths = optparse.parse(args)
|
87
|
-
Configuration.instance.set :path, paths.first || Dir.pwd
|
88
|
-
if @options[:skip_file_patterns] && !@options[:skip_file_patterns].empty?
|
89
|
-
skip_files = @options[:skip_file_patterns].map { |file_pattern|
|
90
|
-
full_file_pattern = File.join(Configuration.instance.get(:path), file_pattern)
|
91
|
-
Dir.glob(full_file_pattern)
|
92
|
-
}.flatten
|
93
|
-
Configuration.instance.set :skip_files, skip_files
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Load all rewriters.
|
98
|
-
def load_rewriters
|
99
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'snippets/**/*.rb')).each { |file| eval(File.read(file)) }
|
100
|
-
|
101
|
-
@options[:snippet_paths].each do |snippet_path|
|
102
|
-
if snippet_path =~ /^http/
|
103
|
-
uri = URI.parse snippet_path
|
104
|
-
eval(uri.read)
|
105
|
-
else
|
106
|
-
eval(File.read(snippet_path))
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# List and print all available rewriters.
|
112
|
-
def list_available_rewriters
|
113
|
-
Rewriter.availables.each do |rewriter|
|
114
|
-
print rewriter.name.to_s + " "
|
115
|
-
end
|
116
|
-
puts
|
117
|
-
end
|
118
|
-
|
119
|
-
# Query and print available rewriters.
|
120
|
-
def query_available_rewriters
|
121
|
-
Rewriter.availables.each do |rewriter|
|
122
|
-
if rewriter.name.include? @options[:query]
|
123
|
-
print rewriter.name + " "
|
124
|
-
end
|
125
|
-
end
|
126
|
-
puts
|
127
|
-
end
|
128
|
-
|
129
|
-
# Show and print one rewriter.
|
130
|
-
def show_rewriter
|
131
|
-
rewriter = Rewriter.fetch(@options[:snippet_name])
|
132
|
-
if rewriter
|
133
|
-
rewriter.process_with_sandbox
|
134
|
-
puts rewriter.description
|
135
|
-
rewriter.sub_snippets.each do |sub_rewriter|
|
136
|
-
puts
|
137
|
-
puts "=" * 80
|
138
|
-
puts "snippet: #{sub_rewriter.name}"
|
139
|
-
puts "=" * 80
|
140
|
-
puts sub_rewriter.description
|
141
|
-
end
|
142
|
-
else
|
143
|
-
puts "snippet #{@options[:snippet_name]} not found"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|