Sha256: 019ec306839bd7094fc4daa70393e82b36eef82a0b2cdbdbec4b1b87c4fc748d

Contents?: true

Size: 1.47 KB

Versions: 60

Compression:

Stored size: 1.47 KB

Contents

module Docile
  # @api private
  #
  # A namespace for functions relating to the execution of a block against a
  # proxy object.
  module Execution
    # Execute a block in the context of an object whose methods represent the
    # commands in a DSL, using a specific proxy class.
    #
    # @param dsl        [Object] context object whose methods make up the
    #                            (initial) DSL
    # @param proxy_type [FallbackContextProxy, ChainingFallbackContextProxy]
    #                            which class to instantiate as proxy context
    # @param args       [Array]  arguments to be passed to the block
    # @param block      [Proc]   the block of DSL commands to be executed
    # @return           [Object] the return value of the block
    def exec_in_proxy_context(dsl, proxy_type, *args, &block)
      block_context = eval('self', block.binding)
      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
    module_function :exec_in_proxy_context
  end
end

Version data entries

60 entries across 52 versions & 15 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/docile-1.1.5/lib/docile/execution.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/docile-1.1.5/lib/docile/execution.rb
tdiary-5.0.9 vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb
docile-1.2.0 lib/docile/execution.rb
tdiary-5.0.7 vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/docile-1.1.5/lib/docile/execution.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/docile-1.1.5/lib/docile/execution.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/docile-1.1.5/lib/docile/execution.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/docile-1.1.5/lib/docile/execution.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/docile-1.1.5/lib/docile/execution.rb
tdiary-5.0.6 vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/docile-1.1.5/lib/docile/execution.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/docile-1.1.5/lib/docile/execution.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/docile-1.1.5/lib/docile/execution.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/docile-1.1.5/lib/docile/execution.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb
tdiary-5.0.5 vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/docile-1.1.5/lib/docile/execution.rb
tdiary-5.0.4 vendor/bundle/gems/docile-1.1.5/lib/docile/execution.rb