Module: Remi::Dsl Private
- Defined in:
- lib/remi/dsl.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
A namespace for functions relating to the execution of a block against a proxy object.
Much of this code was borrowed from Docile and was modified to support different fallback contexts.
Class Method Summary collapse
-
.dsl_eval(dsl, fallback_dsl, *args, &block) ⇒ Object
private
Execute a block in the context of an object whose methods represent the commands in a DSL.
- .dsl_return(dsl, fallback_dsl, *args, &block) ⇒ Object private
-
.exec_in_proxy_context(dsl, fallback_dsl, proxy_type, *args, &block) ⇒ Object
private
Execute a block in the context of an object whose methods represent the commands in a DSL, using a specific proxy class.
Class Method Details
.dsl_eval(dsl, fallback_dsl, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use with an imperative DSL (commands modify the context object)
Execute a block in the context of an object whose methods represent the commands in a DSL.
Use this method to execute an imperative DSL, which means that:
- Each command mutates the state of the DSL context object
- The return value of each command is ignored
- The final return value is the original context object
63 64 65 66 |
# File 'lib/remi/dsl.rb', line 63 def dsl_eval(dsl, fallback_dsl, *args, &block) exec_in_proxy_context(dsl, fallback_dsl, Docile::FallbackContextProxy, *args, &block) dsl end |
.dsl_return(dsl, fallback_dsl, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'lib/remi/dsl.rb', line 69 def dsl_return(dsl, fallback_dsl, *args, &block) exec_in_proxy_context(dsl, fallback_dsl, Docile::FallbackContextProxy, *args, &block) end |
.exec_in_proxy_context(dsl, fallback_dsl, proxy_type, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute a block in the context of an object whose methods represent the commands in a DSL, using a specific proxy class.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/remi/dsl.rb', line 26 def exec_in_proxy_context(dsl, fallback_dsl, proxy_type, *args, &block) block_context = fallback_dsl proxy_context = proxy_type.new(dsl, block_context) begin block_context.instance_variables.each do |ivar| value_from_block = block_context.instance_variable_get(ivar) proxy_context.instance_variable_set(ivar, value_from_block) end proxy_context.instance_exec(*args, &block) ensure block_context.instance_variables.each do |ivar| value_from_dsl_proxy = proxy_context.instance_variable_get(ivar) block_context.instance_variable_set(ivar, value_from_dsl_proxy) end end end |