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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee3374fb46922e5b590efa36db97d72a9e44abce
4
- data.tar.gz: 3fe3c251671150387708c7e882078198956443fe
3
+ metadata.gz: 060a67494f8695693b472fe25ed39d9af6021a28
4
+ data.tar.gz: 67485c8861388275535bd8e3a0ab775ae558220d
5
5
  SHA512:
6
- metadata.gz: 6422babf1c7b32bf5c5201aa8eb8e56fb4cfe7b7082e5ab0c7e0d3cfd6fec55250475bcbf789c71cc25dcbcf4364e74d7e2c7aadf6e4c967c303ea8e26be9ed7
7
- data.tar.gz: 71d807430eb04e21a047625d59786be237ef6f4de3465095a5a9524d7a5384eb001ddf6bee14b7a5092dbfd2580385941449aea62e8f7b7a22432da7e8c05fd5
6
+ metadata.gz: a2e3ecbb02ee560b8fed9c0a968bfbc35d2eea5598a94147bbab9a26895813e6de414a94375cbfd5e24987dbe9960f87a1518b7a957e2cbf660a25fe55f16fff
7
+ data.tar.gz: e0926950d6b9b55c3ab138a095706dcdbf99cbc92a2789e33db9c83e47c2a8026b4adccd07c6bb2a1c55aebea9ad9ceedce542cd023b993cb05ef1b01882c10a
data/.travis.yml CHANGED
@@ -2,5 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0
6
5
  - 2.1.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.1
4
+
5
+ * Return empty array if no available rewriters
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  * Abstract from synvert
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Richard Huang
1
+ Copyright (c) 2014 Xinmin Labs
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -24,6 +24,7 @@ Or install it yourself as:
24
24
  ## Documentation
25
25
 
26
26
  [Website][1]
27
+
27
28
  [RDoc][2]
28
29
 
29
30
  ## Contributing
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -70,7 +70,7 @@ module Synvert::Core
70
70
  #
71
71
  # @return [Array<Synvert::Core::Rewriter>]
72
72
  def availables
73
- @rewriters.values
73
+ @rewriters ? @rewriters.values : []
74
74
  end
75
75
 
76
76
  # Clear all registered rewriters.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ module Synvert::Core
4
+ describe Configuration do
5
+ it 'sets / gets' do
6
+ Configuration.instance.set :key, 'value'
7
+ expect(Configuration.instance.get :key).to eq 'value'
8
+ end
9
+ end
10
+ end
@@ -143,10 +143,16 @@ module Synvert::Core
143
143
  Rewriter.call 'rewriter'
144
144
  end
145
145
 
146
- it 'registers and lists all available rewriters' do
147
- rewriter1 = Rewriter.new 'rewriter1'
148
- rewriter2 = Rewriter.new 'rewriter2'
149
- expect(Rewriter.availables).to eq [rewriter1, rewriter2]
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.0
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
@@ -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