dslblend 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dslblend/base.rb +18 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f8db1ece35e0f96e0a9355492e873a2fdb0ea98062145c5ce2d2f32392c14f7
4
- data.tar.gz: e778123e58e4f9c74db96875343171bb0eab4a3992d506684efe61700161b324
3
+ metadata.gz: ef1b7e343e127a2b8235cda96b45387384cedca06b2970bc1f22c1c86bdf37b7
4
+ data.tar.gz: 4d241a1657d4c4061fd5a19cc6cf133194abe2d038c0c4e3125de31f89087aa4
5
5
  SHA512:
6
- metadata.gz: 381149a2035a255f142467e2a3644eb285dc908cd48678611f158e513f82bb128045621a5d7a86daa4b9296246f306693274fe5eb96b2d37be583b24b9c728f4
7
- data.tar.gz: 559c120d3290496ae63bbafa66d34825ddec9fba46d524f63f9a949cf242e6379c19697c3e7a1f523de7b42d679b5a10fa92c5d84b81c94dff2e4ea77de74b0e
6
+ metadata.gz: a30895d4f9305a45c3bb455d54d8270e766fcd51e39b4aa8b4016f49da0ba8712c9b4c408b75484b81248d1f7122004ffa440f2b4f4518c18fe3cef6a569e9b8
7
+ data.tar.gz: dc53c5878eb746849cba89ae388f4fb935639e8ea37ef6248c2ddc160a7e4a5d94cff995ccbb53c297a63c22f3533ee9b728f9ab43267a51b078e24dfe634180
data/lib/dslblend/base.rb CHANGED
@@ -6,13 +6,29 @@ module Dslblend
6
6
  @_additional_providers = additional_providers
7
7
  end
8
8
 
9
- def evaluate(&block)
9
+ def evaluate(backfire_vars: false, &block)
10
+ # Auto-detect main provider if it is not given yet
10
11
  @_main_provider ||= eval 'self', block.binding, __FILE__, __LINE__
12
+
13
+ # Transfer instance variables from main provider instance to dsl instance, ignore those starting with "_"
11
14
  @_main_provider.instance_variables.each do |instance_variable|
12
15
  next if instance_variable.to_s.start_with?('@_')
13
16
  instance_variable_set(instance_variable, @_main_provider.instance_variable_get(instance_variable))
14
17
  end
15
- instance_eval(&block)
18
+
19
+ # Evaluate block within the DSL
20
+ block_return_value = instance_eval(&block)
21
+
22
+ # If backfire is enabled, transfer dsl instance variables back to main provider instance, ignore those starting with "_"
23
+ if backfire_vars
24
+ instance_variables.each do |instance_variable|
25
+ next if instance_variable.to_s.start_with?('@_')
26
+
27
+ @_main_provider.instance_variable_set(instance_variable, instance_variable_get(instance_variable))
28
+ end
29
+ end
30
+
31
+ return block_return_value
16
32
  end
17
33
 
18
34
  def method_missing(method, *args, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dslblend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Kalbermatter