synvert 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/lib/synvert/cli.rb +11 -0
- data/lib/synvert/rewriter/instance.rb +26 -24
- data/lib/synvert/snippets/rails/convert_dynamic_finders.rb +6 -6
- data/lib/synvert/version.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c931de2635de5862893c1d3ed8640bf9c34b0c
|
4
|
+
data.tar.gz: e0970c81b8cea4465a7fc731acceb2b669feed1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea4728906ffb22035dfd91e3f04c6f5d74529b8636a25a0ccf21389d9b2e9a6c928583e22a6b7170b36098cb58f9392ec6664af05230cb5faf132f3978a7dba
|
7
|
+
data.tar.gz: d9a67c7c30139eb2ec92a31ff6aab0a26cde7ded6c98d31d446b29c3146fc399a4ba571ad8cf2794ac691bd5c97c144dda9bae5fee7a388b47e52c16cd196e0f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,7 @@ Usage: synvert [project_path]
|
|
27
27
|
-d, --load SNIPPET_PATHS load additional snippets, snippet paths can be local file path or remote http url
|
28
28
|
-l, --list list all available snippets
|
29
29
|
-q, --query QUERY query specified snippets
|
30
|
+
--skip FILE_PATTERNS skip specified files or directories, separated by comma, e.g. app/models/post.rb,vendor/plugins/**/*.rb
|
30
31
|
-s, --show SNIPPET_NAME show specified snippet description
|
31
32
|
-r, --run SNIPPET_NAMES run specified snippets
|
32
33
|
-v, --version show this version
|
data/lib/synvert/cli.rb
CHANGED
@@ -16,6 +16,7 @@ module Synvert
|
|
16
16
|
# Initialize a CLI.
|
17
17
|
def initialize
|
18
18
|
@options = {command: 'run', snippet_paths: [], snippet_names: []}
|
19
|
+
Configuration.instance.set :skip_files, []
|
19
20
|
end
|
20
21
|
|
21
22
|
# Run the CLI.
|
@@ -67,6 +68,9 @@ module Synvert
|
|
67
68
|
@options[:command] = 'query'
|
68
69
|
@options[:query] = query
|
69
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
|
70
74
|
opts.on '-s', '--show SNIPPET_NAME', 'show specified snippet description' do |snippet_name|
|
71
75
|
@options[:command] = 'show'
|
72
76
|
@options[:snippet_name] = snippet_name
|
@@ -81,6 +85,13 @@ module Synvert
|
|
81
85
|
end
|
82
86
|
paths = optparse.parse(args)
|
83
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
|
84
95
|
end
|
85
96
|
|
86
97
|
# Load all rewriters.
|
@@ -32,30 +32,32 @@ module Synvert
|
|
32
32
|
parser = Parser::CurrentRuby.new
|
33
33
|
file_pattern = File.join(Configuration.instance.get(:path), @file_pattern)
|
34
34
|
Dir.glob(file_pattern).each do |file_path|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
35
|
+
unless Configuration.instance.get(:skip_files).include? file_path
|
36
|
+
begin
|
37
|
+
source = File.read(file_path)
|
38
|
+
buffer = Parser::Source::Buffer.new file_path
|
39
|
+
buffer.source = source
|
40
|
+
|
41
|
+
parser.reset
|
42
|
+
ast = parser.parse buffer
|
43
|
+
|
44
|
+
@current_file = file_path
|
45
|
+
@current_source = source
|
46
|
+
@current_node = ast
|
47
|
+
instance_eval &@block
|
48
|
+
@current_node = ast
|
49
|
+
|
50
|
+
@actions.sort!
|
51
|
+
check_conflict_actions
|
52
|
+
@actions.reverse.each do |action|
|
53
|
+
source[action.begin_pos...action.end_pos] = action.rewritten_code
|
54
|
+
source = remove_code_or_whole_line(source, action.line)
|
55
|
+
end
|
56
|
+
@actions = []
|
57
|
+
|
58
|
+
File.write file_path, source
|
59
|
+
end while !@conflict_actions.empty?
|
60
|
+
end
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
@@ -23,7 +23,7 @@ It converts rails dynamic finders to arel syntax.
|
|
23
23
|
|
24
24
|
within_files '**/*.rb' do
|
25
25
|
# find_all_by_... => where(...)
|
26
|
-
with_node type: 'send', message:
|
26
|
+
with_node type: 'send', message: /^find_all_by_/ do
|
27
27
|
hash_params = dynamic_finder_to_hash("find_all_by_")
|
28
28
|
if node.receiver
|
29
29
|
replace_with "{{receiver}}.where(#{hash_params})"
|
@@ -33,7 +33,7 @@ It converts rails dynamic finders to arel syntax.
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# find_by_... => where(...).first
|
36
|
-
with_node type: 'send', message:
|
36
|
+
with_node type: 'send', message: /^find_by_/ do
|
37
37
|
if :find_by_id == node.message
|
38
38
|
if node.receiver
|
39
39
|
replace_with "{{receiver}}.find({{arguments}})"
|
@@ -51,7 +51,7 @@ It converts rails dynamic finders to arel syntax.
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# find_last_by_... => where(...).last
|
54
|
-
with_node type: 'send', message:
|
54
|
+
with_node type: 'send', message: /^find_last_by_/ do
|
55
55
|
hash_params = dynamic_finder_to_hash("find_last_by_")
|
56
56
|
if node.receiver
|
57
57
|
replace_with "{{receiver}}.where(#{hash_params}).last"
|
@@ -61,7 +61,7 @@ It converts rails dynamic finders to arel syntax.
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# scoped_by_... => where(...)
|
64
|
-
with_node type: 'send', message:
|
64
|
+
with_node type: 'send', message: /^scoped_by_/ do
|
65
65
|
hash_params = dynamic_finder_to_hash("scoped_by_")
|
66
66
|
if node.receiver
|
67
67
|
replace_with "{{receiver}}.where(#{hash_params})"
|
@@ -71,7 +71,7 @@ It converts rails dynamic finders to arel syntax.
|
|
71
71
|
end
|
72
72
|
|
73
73
|
# find_or_initialize_by_... => find_or_initialize_by(...)
|
74
|
-
with_node type: 'send', message:
|
74
|
+
with_node type: 'send', message: /^find_or_initialize_by_/ do
|
75
75
|
hash_params = dynamic_finder_to_hash("find_or_initialize_by_")
|
76
76
|
if node.receiver
|
77
77
|
replace_with "{{receiver}}.find_or_initialize_by(#{hash_params})"
|
@@ -81,7 +81,7 @@ It converts rails dynamic finders to arel syntax.
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# find_or_create_by_... => find_or_create_by(...)
|
84
|
-
with_node type: 'send', message:
|
84
|
+
with_node type: 'send', message: /^find_or_create_by_/ do
|
85
85
|
hash_params = dynamic_finder_to_hash("find_or_create_by_")
|
86
86
|
if node.receiver
|
87
87
|
replace_with "{{receiver}}.find_or_create_by(#{hash_params})"
|
data/lib/synvert/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|