synvert-core 1.33.3 → 1.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/synvert/core/configuration.rb +26 -0
- data/lib/synvert/core/rewriter.rb +24 -0
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/configuration_spec.rb +25 -0
- data/spec/synvert/core/rewriter_spec.rb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7407325ab10af6e8e90b2a2e10bc737686a555603f362319779a2a9868d8ba71
|
4
|
+
data.tar.gz: eb2f33a8ea48fc4836af3529ca4f684c7c8e1c98a797d55703ada5b60505878e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c762d52252e31200861d30d418f4f634ff4f9dfcacd1d11964865be664118a78a6a76362614232f5a1b465ad8862d974adfa1f3baed6395cac6dac000ebffc
|
7
|
+
data.tar.gz: df130135e5df9453b3f4d6847c68aaf0703fb31765b384ca86c31ca52c0d60c60f64717ac2b26457d872a5a523a640cb5f6a9b7715fefe2b3df2008f691e3b01
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,9 @@ DSLs are as follows
|
|
70
70
|
* [helper_method](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
|
71
71
|
* [add_snippet](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
|
72
72
|
* [call_helper](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#call_helper-instance_method) - call a shared rewriter
|
73
|
+
* [with_configurations](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#with_configurations-instance_method) - execute a block of code with temporary configurations
|
74
|
+
* [save_data](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#save_data-instance_method) - save data
|
75
|
+
* [load_data](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#load_data-instance_method) - load data
|
73
76
|
|
74
77
|
Scopes:
|
75
78
|
|
@@ -100,6 +100,32 @@ module Synvert::Core
|
|
100
100
|
def test_result
|
101
101
|
@test_result || 'actions'
|
102
102
|
end
|
103
|
+
|
104
|
+
# Temporarily sets the specified configurations, executes the given block, and then restores the original configurations.
|
105
|
+
#
|
106
|
+
# @param configurations [Hash] The configurations to be set temporarily.
|
107
|
+
# @yield The block of code to be executed.
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# with_temporary_configurations({ number_of_workers: 1 }) do
|
111
|
+
# # Code to be executed with temporary configurations
|
112
|
+
# end
|
113
|
+
def with_temporary_configurations(configurations, &block)
|
114
|
+
old_instance_variables = instance_variables.reduce({}) do |hash, var|
|
115
|
+
hash[var] = instance_variable_get(var)
|
116
|
+
hash
|
117
|
+
end
|
118
|
+
|
119
|
+
configurations.each do |variable, value|
|
120
|
+
instance_variable_set("@#{variable}", value)
|
121
|
+
end
|
122
|
+
|
123
|
+
block.call
|
124
|
+
|
125
|
+
old_instance_variables.each do |var, value|
|
126
|
+
instance_variable_set(var, value)
|
127
|
+
end
|
128
|
+
end
|
103
129
|
end
|
104
130
|
end
|
105
131
|
end
|
@@ -409,6 +409,30 @@ module Synvert::Core
|
|
409
409
|
@helpers << { name: name, block: block }
|
410
410
|
end
|
411
411
|
|
412
|
+
# Executes a block of code with temporary configurations.
|
413
|
+
#
|
414
|
+
# @param configurations [Hash] The temporary configurations to apply.
|
415
|
+
# @yield The block of code to execute.
|
416
|
+
def with_configurations(configurations, &block)
|
417
|
+
Configuration.with_temporary_configurations(configurations, &block)
|
418
|
+
end
|
419
|
+
|
420
|
+
# Saves data with a given key and value.
|
421
|
+
#
|
422
|
+
# @param key [Symbol] the key to identify the data
|
423
|
+
# @param value [Object] the value to be saved
|
424
|
+
def save_data(key, value)
|
425
|
+
Synvert::Core.instance_variable_set("@#{key}", value)
|
426
|
+
end
|
427
|
+
|
428
|
+
# Loads data with the given key.
|
429
|
+
#
|
430
|
+
# @param key [Symbol] the key of the data to be loaded
|
431
|
+
# @return [Object] the data loaded
|
432
|
+
def load_data(key)
|
433
|
+
Synvert::Core.instance_variable_get("@#{key}")
|
434
|
+
end
|
435
|
+
|
412
436
|
private
|
413
437
|
|
414
438
|
# Handle one file.
|
data/lib/synvert/core/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Synvert::Core
|
4
|
+
RSpec.describe Configuration do
|
5
|
+
after do
|
6
|
+
Configuration.number_of_workers = nil
|
7
|
+
Configuration.strict = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.with_temporary_configurations' do
|
11
|
+
it 'temporarily sets instance variables and restores them after block execution' do
|
12
|
+
Configuration.number_of_workers = 4
|
13
|
+
Configuration.strict = true
|
14
|
+
|
15
|
+
Configuration.with_temporary_configurations(number_of_workers: 1, strict: false) do
|
16
|
+
expect(Configuration.number_of_workers).to eq(1)
|
17
|
+
expect(Configuration.strict).to eq(false)
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(Configuration.number_of_workers).to eq(4)
|
21
|
+
expect(Configuration.strict).to eq(true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -395,6 +395,18 @@ module Synvert::Core
|
|
395
395
|
expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
|
396
396
|
end
|
397
397
|
|
398
|
+
it 'parses save_data and load_data' do
|
399
|
+
data = nil
|
400
|
+
rewriter =
|
401
|
+
Rewriter.new 'group', 'name' do
|
402
|
+
hash = { foo: 'bar' }
|
403
|
+
save_data :object, hash
|
404
|
+
data = load_data :object
|
405
|
+
end
|
406
|
+
rewriter.process
|
407
|
+
expect(data).to eq({ foo: 'bar' })
|
408
|
+
end
|
409
|
+
|
398
410
|
describe 'class methods' do
|
399
411
|
before :each do
|
400
412
|
Rewriter.clear
|
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.
|
4
|
+
version: 1.34.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: 2024-02-
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- lib/synvert/core/version.rb
|
197
197
|
- spec/spec_helper.rb
|
198
198
|
- spec/support/parser_helper.rb
|
199
|
+
- spec/synvert/core/configuration_spec.rb
|
199
200
|
- spec/synvert/core/engine/erb_spec.rb
|
200
201
|
- spec/synvert/core/engine/haml_spec.rb
|
201
202
|
- spec/synvert/core/engine/slim_spec.rb
|
@@ -242,6 +243,7 @@ summary: convert ruby code to better syntax.
|
|
242
243
|
test_files:
|
243
244
|
- spec/spec_helper.rb
|
244
245
|
- spec/support/parser_helper.rb
|
246
|
+
- spec/synvert/core/configuration_spec.rb
|
245
247
|
- spec/synvert/core/engine/erb_spec.rb
|
246
248
|
- spec/synvert/core/engine/haml_spec.rb
|
247
249
|
- spec/synvert/core/engine/slim_spec.rb
|