dslblend 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dslblend/base.rb +28 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c89e926215c62c9780f739ed69deda2f20629633836b896bcae2be7eca49abe4
|
4
|
+
data.tar.gz: c9a07e5b73ab6a4dc20c3ff5cbfb4c10702c78de51c655771775d208083c7658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
10
|
-
|
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
|
-
|
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
|
-
#
|
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)
|