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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a783bc0774369db2befc3887b41e955cae2adbe0
4
- data.tar.gz: a5969647ad5a16adea6f8da5144c92acbc5011e7
3
+ metadata.gz: a8c931de2635de5862893c1d3ed8640bf9c34b0c
4
+ data.tar.gz: e0970c81b8cea4465a7fc731acceb2b669feed1d
5
5
  SHA512:
6
- metadata.gz: 8df94cd6b38513ad2f99b24b426f8275f929c1a98746a628ff6a47908c71372bc4bb379501c389d486b1b040435ed5a2185b4b72fe817eb51d32447d3e271203
7
- data.tar.gz: 79ab182f79f99c14fe07e3dda0e6ddc99d587355b05d1cff763fe8fc2a054c24884628a45a2b323910ea95679d831fba5aa232354c9c3ad0278abfc5829efe2c
6
+ metadata.gz: 1ea4728906ffb22035dfd91e3f04c6f5d74529b8636a25a0ccf21389d9b2e9a6c928583e22a6b7170b36098cb58f9392ec6664af05230cb5faf132f3978a7dba
7
+ data.tar.gz: d9a67c7c30139eb2ec92a31ff6aab0a26cde7ded6c98d31d446b29c3146fc399a4ba571ad8cf2794ac691bd5c97c144dda9bae5fee7a388b47e52c16cd196e0f
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.17
4
+
5
+ * Polish convert_rails_dynamic_finders snippet.
6
+ * Add --skip option to cli to skip files and directories.
7
+
3
8
  ## 0.0.16
4
9
 
5
10
  * Add -v, --version cli option.
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
@@ -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
- begin
36
- source = File.read(file_path)
37
- buffer = Parser::Source::Buffer.new file_path
38
- buffer.source = source
39
-
40
- parser.reset
41
- ast = parser.parse buffer
42
-
43
- @current_file = file_path
44
- @current_source = source
45
- @current_node = ast
46
- instance_eval &@block
47
- @current_node = ast
48
-
49
- @actions.sort!
50
- check_conflict_actions
51
- @actions.reverse.each do |action|
52
- source[action.begin_pos...action.end_pos] = action.rewritten_code
53
- source = remove_code_or_whole_line(source, action.line)
54
- end
55
- @actions = []
56
-
57
- File.write file_path, source
58
- end while !@conflict_actions.empty?
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: /find_all_by_/ do
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: /find_by_/ do
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: /find_last_by_/ do
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: /scoped_by_/ do
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: /find_or_initialize_by_/ do
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: /find_or_create_by_/ do
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})"
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.0.16"
4
+ VERSION = "0.0.17"
5
5
  end
@@ -19,4 +19,8 @@ RSpec.configure do |config|
19
19
  config.filter_run :focus
20
20
 
21
21
  config.order = 'random'
22
+
23
+ config.before do
24
+ Synvert::Configuration.instance.set :skip_files, []
25
+ end
22
26
  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.0.16
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-18 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser