synvert-core 1.10.0 → 1.11.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
2
  SHA256:
3
- metadata.gz: 16de1af456b15373297aebe409711e1725bb329e3da7d4fa8d84023348ceb236
4
- data.tar.gz: e034ccf44cfce96335f10a38d5aa36793faa08c84e8d75509fc658824cf64676
3
+ metadata.gz: 0663ba61695ae5b47f27e9a23f1edbfe31d3746f9b3e02a79315a827fae6f36c
4
+ data.tar.gz: 8199c6c8a122555bfbf0df0ef79f6bd96ade0cdfe472d81d6abe4cccde3b6c59
5
5
  SHA512:
6
- metadata.gz: 3f745e87c308b417c5938c2731af00254abe5beba70472bca1ebfdf534127b7df8f6ab33261b8eb5d31d33deaa471927a780a14720f0ee406eea44f5a7e06495
7
- data.tar.gz: ac2c35d21a4e6558b14c861966c6326446926bc27cc9e2d278757df31cf68a33142e62d47f9d40e5ec72c1d3fd8efde6574046e00506c9a12d0a800580a00023
6
+ metadata.gz: 3609b9bdb845681c9dd71d9d0eca4985d43203ce28fb1e874e9538322f8205995d77f5b8c2b43fb11caf698a69772c3e7bdd5114a709e4513313339870576a5e
7
+ data.tar.gz: 952578268a2c8cba6dcd2883141fe5977917594ea01b76e51e93032fc71225c813b9021ec1852c3a93d76f6438f30f9975ac47b36c5da3d7c5805fa15763fa9e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.11.0 (2022-10-11)
4
+
5
+ * Add `Configuration.number_of_workers`
6
+ * Test rewriter in parallel
7
+
8
+ ## 1.10.1 (2022-10-09)
9
+
10
+ * Do not reset `@options`
11
+ * `Rewriter.fetch` does not raise error if rewriter not found
12
+
3
13
  ## 1.10.0 (2022-10-09)
4
14
 
5
15
  * Eval snippet by http url, file path or snippet name
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.10.0)
4
+ synvert-core (1.11.0)
5
5
  activesupport (< 7.0.0)
6
6
  erubis
7
7
  node_mutation
8
8
  node_query
9
+ parallel
9
10
  parser
10
11
  parser_node_ext
11
12
 
@@ -57,6 +58,7 @@ GEM
57
58
  notiffany (0.1.3)
58
59
  nenv (~> 0.1)
59
60
  shellany (~> 0.0)
61
+ parallel (1.22.1)
60
62
  parser (3.1.2.1)
61
63
  ast (~> 2.4.1)
62
64
  parser_node_ext (0.4.0)
@@ -8,7 +8,8 @@ module Synvert::Core
8
8
  # @!attribute [w] skip_paths
9
9
  # @!attribute [w] only_paths
10
10
  # @!attribute [w] show_run_process
11
- attr_writer :root_path, :skip_paths, :only_paths, :show_run_process
11
+ # @!attribute [w] number_of_workers
12
+ attr_writer :root_path, :skip_paths, :only_paths, :show_run_process, :number_of_workers
12
13
 
13
14
  # Get the path.
14
15
  #
@@ -37,6 +38,13 @@ module Synvert::Core
37
38
  def show_run_process
38
39
  @show_run_process || false
39
40
  end
41
+
42
+ # Number of workers
43
+ #
44
+ # @return [Integer] default is 1
45
+ def number_of_workers
46
+ @number_of_workers || 1
47
+ end
40
48
  end
41
49
  end
42
50
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require 'parallel'
2
3
 
3
4
  module Synvert::Core
4
5
  # Instance is an execution unit, it finds specified ast nodes,
@@ -41,8 +42,14 @@ module Synvert::Core
41
42
  # It finds specified files, for each file, it executes the block code, tests the original code,
42
43
  # then returns the actions.
43
44
  def test
44
- get_file_paths.map do |file_path|
45
- test_file(file_path)
45
+ if Configuration.number_of_workers > 1
46
+ Parallel.map(get_file_paths, in_processes: Configuration.number_of_workers) do |file_path|
47
+ test_file(file_path)
48
+ end
49
+ else
50
+ get_file_paths.map do |file_path|
51
+ test_file(file_path)
52
+ end
46
53
  end
47
54
  end
48
55
 
@@ -51,14 +51,10 @@ module Synvert::Core
51
51
  # @param group [String] rewrtier group.
52
52
  # @param name [String] rewrtier name.
53
53
  # @return [Synvert::Core::Rewriter] the matching rewriter.
54
- # @raise [Synvert::Core::RewriterNotFound] if the registered rewriter is not found.
55
54
  def fetch(group, name)
56
55
  group = group.to_s
57
56
  name = name.to_s
58
- rewriter = rewriters.dig(group, name)
59
- raise RewriterNotFound, "Rewriter #{group} #{name} not found" unless rewriter
60
-
61
- rewriter
57
+ rewriters.dig(group, name)
62
58
  end
63
59
 
64
60
  # Get all available rewriters
@@ -136,24 +132,16 @@ module Synvert::Core
136
132
  # It will call the block but doesn't change any file.
137
133
  def process_with_sandbox
138
134
  @options[:run_instance] = false
139
- begin
140
- process
141
- ensure
142
- @options[:run_instance] = true
143
- end
135
+ process
144
136
  end
145
137
 
146
138
  def test
147
139
  @options[:write_to_file] = false
148
- begin
149
- @affected_files = Set.new
150
- instance_eval(&@block)
140
+ @affected_files = Set.new
141
+ instance_eval(&@block)
151
142
 
152
- if !@affected_files.empty? && @redo_until_no_change # redo
153
- test
154
- end
155
- ensure
156
- @options[:write_to_file] = true
143
+ if !@affected_files.empty? && @redo_until_no_change # redo
144
+ test
157
145
  end
158
146
  @test_results
159
147
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.10.0'
5
+ VERSION = '1.11.0'
6
6
  end
7
7
  end
data/lib/synvert/core.rb CHANGED
@@ -17,8 +17,6 @@ module Synvert
17
17
  autoload :Configuration, 'synvert/core/configuration'
18
18
  autoload :Rewriter, 'synvert/core/rewriter'
19
19
  autoload :Engine, 'synvert/core/engine'
20
- autoload :RewriterNotFound, 'synvert/core/exceptions'
21
- autoload :MethodNotSupported, 'synvert/core/exceptions'
22
20
  autoload :Utils, 'synvert/core/utils'
23
21
  end
24
22
  end
@@ -238,15 +238,6 @@ module Synvert::Core
238
238
  rewriter.process
239
239
  expect(Rewriter.fetch('group', 'sub_rewriter')).not_to be_nil
240
240
  end
241
-
242
- it 'raises RewriterNotFound' do
243
- rewriter =
244
- Rewriter.new 'group', 'name' do
245
- add_snippet :group, :not_exist
246
- end
247
- expect { rewriter.process }
248
- .to raise_error(RewriterNotFound)
249
- end
250
241
  end
251
242
 
252
243
  it 'parses helper_method' do
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency "node_mutation"
26
26
  spec.add_runtime_dependency "parser"
27
27
  spec.add_runtime_dependency "parser_node_ext"
28
+ spec.add_runtime_dependency "parallel"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-09 00:00:00.000000000 Z
11
+ date: 2022-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: parallel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: convert ruby code to better syntax automatically.
98
112
  email:
99
113
  - flyerhzm@gmail.com
@@ -116,7 +130,6 @@ files:
116
130
  - lib/synvert/core/configuration.rb
117
131
  - lib/synvert/core/engine.rb
118
132
  - lib/synvert/core/engine/erb.rb
119
- - lib/synvert/core/exceptions.rb
120
133
  - lib/synvert/core/node_ext.rb
121
134
  - lib/synvert/core/rewriter.rb
122
135
  - lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Synvert::Core
4
- # Rewriter not found exception.
5
- class RewriterNotFound < RuntimeError
6
- end
7
-
8
- # Method not supported exception.
9
- class MethodNotSupported < RuntimeError
10
- end
11
- end