dslblend 0.0.2 → 0.0.3

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 +28 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef1b7e343e127a2b8235cda96b45387384cedca06b2970bc1f22c1c86bdf37b7
4
- data.tar.gz: 4d241a1657d4c4061fd5a19cc6cf133194abe2d038c0c4e3125de31f89087aa4
3
+ metadata.gz: c89e926215c62c9780f739ed69deda2f20629633836b896bcae2be7eca49abe4
4
+ data.tar.gz: c9a07e5b73ab6a4dc20c3ff5cbfb4c10702c78de51c655771775d208083c7658
5
5
  SHA512:
6
- metadata.gz: a30895d4f9305a45c3bb455d54d8270e766fcd51e39b4aa8b4016f49da0ba8712c9b4c408b75484b81248d1f7122004ffa440f2b4f4518c18fe3cef6a569e9b8
7
- data.tar.gz: dc53c5878eb746849cba89ae388f4fb935639e8ea37ef6248c2ddc160a7e4a5d94cff995ccbb53c297a63c22f3533ee9b728f9ab43267a51b078e24dfe634180
6
+ metadata.gz: c431581d08341cfcffa1bb085296cec9afa250e87c50a6fa5f4c0de6ac442c7f3a317bec9053c61712b0fea353bb65df4c6c4b04a4a21f25956d6472a7f10825
7
+ data.tar.gz: 730bf193a796e2d3ad39cac1ae63c8d70d234823c636615232f13c8639558ecb9957421f697fb2c63421e3ae5671f4d23a61e5c1cac013b4b98ffb5d8d002431
data/lib/dslblend/base.rb CHANGED
@@ -6,38 +6,52 @@ module Dslblend
6
6
  @_additional_providers = additional_providers
7
7
  end
8
8
 
9
- def evaluate(backfire_vars: false, &block)
10
- # Auto-detect main provider if it is not given yet
9
+ # Usually, you will not need to use the methods prefixed with `_dslblend_`. However, they can come in
10
+ # useful if you have special needs such as preparing a context for HAML engine etc.
11
+
12
+ # Auto-detect main provider if it is not given yet
13
+ def _dslblend_detect_main_provider(block)
11
14
  @_main_provider ||= eval 'self', block.binding, __FILE__, __LINE__
15
+ end
12
16
 
13
- # Transfer instance variables from main provider instance to dsl instance, ignore those starting with "_"
17
+ # Transfer instance variables from main provider instance to dsl instance, ignore those starting with "_"
18
+ def _dslblend_transfer_inst_vars_from_main_provider
14
19
  @_main_provider.instance_variables.each do |instance_variable|
15
20
  next if instance_variable.to_s.start_with?('@_')
16
21
  instance_variable_set(instance_variable, @_main_provider.instance_variable_get(instance_variable))
17
22
  end
23
+ end
24
+
25
+ # Transfer dsl instance variables back to main provider instance, ignore those starting with "_"
26
+ def _dslblend_backfire_inst_vars_to_main_provider
27
+ instance_variables.each do |instance_variable|
28
+ next if instance_variable.to_s.start_with?('@_')
29
+ @_main_provider.instance_variable_set(instance_variable, instance_variable_get(instance_variable))
30
+ end
31
+ end
32
+
33
+ def evaluate(backfire_vars: false, &block)
34
+ # Prepare this instance
35
+ _dslblend_detect_main_provider(block)
36
+ _dslblend_transfer_inst_vars_from_main_provider
18
37
 
19
38
  # Evaluate block within the DSL
20
39
  block_return_value = instance_eval(&block)
21
40
 
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
41
+ # Write back vars if requested
42
+ _dslblend_backfire_inst_vars_to_main_provider if backfire_vars
30
43
 
44
+ # Allow sending back information from the block to the caller of `evaluate`
31
45
  return block_return_value
32
46
  end
33
47
 
34
- def method_missing(method, *args, &block)
48
+ def method_missing(method, *args, **kwargs, &block)
35
49
  @_additional_providers.each do |additional_provider|
36
50
  if additional_provider.respond_to?(method)
37
- return additional_provider.send(method, *args, &block)
51
+ return additional_provider.send(method, *args, **kwargs, &block)
38
52
  end
39
53
  end
40
- @_main_provider.send method, *args, &block
54
+ @_main_provider.send method, *args, **kwargs, &block
41
55
  end
42
56
 
43
57
  def respond_to_missing?(method, include_all)
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Kalbermatter