class Babl::Utils::DslProxy
The idea is to make it possible to call method defined in block's context in addition to DSL methods. Inspired from github.com/ms-ati/docile/blob/master/lib/docile/fallback_context_proxy.rb, but here we do not try to handle instance variables, because as far as I know there is no way to do it correctly.
Constants
- NON_PROXIED_METHODS
Public Class Methods
eval(dsl, &block)
click to toggle source
# File lib/babl/utils/dsl_proxy.rb, line 35 def self.eval(dsl, &block) new(dsl, block.binding.receiver).instance_exec(&block) end
new(receiver, fallback)
click to toggle source
# File lib/babl/utils/dsl_proxy.rb, line 39 def initialize(receiver, fallback) @__receiver__ = receiver @__fallback__ = fallback end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
rubocop:disable Style/MethodMissingSuper
# File lib/babl/utils/dsl_proxy.rb, line 21 def method_missing(method, *args, &block) if @__receiver__.respond_to?(method) @__receiver__.__send__(method, *args, &block) else @__fallback__.__send__(method, *args, &block) end end
respond_to_missing?(method, include_private = false)
click to toggle source
rubocop:enable Style/MethodMissingSuper
# File lib/babl/utils/dsl_proxy.rb, line 30 def respond_to_missing?(method, include_private = false) @__receiver__.respond_to?(method, include_private) || @__fallback__.respond_to?(method, include_private) end