mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Add a simple Proc extension to support bindings (#1240)
This removes the dependency on the contextual_proc gem Fixes: #1238
This commit is contained in:
24
spec/support/binding_proc.rb
Normal file
24
spec/support/binding_proc.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
##
|
||||
# A simple extension of the Proc class that supports setting a custom binding
|
||||
# and evaluates everything in the Proc using the new binding.
|
||||
|
||||
class ProcWithBinding < Proc
|
||||
##
|
||||
# Set the binding for this instance
|
||||
|
||||
def apply_binding(bind, *args)
|
||||
@binding = bind
|
||||
instance_exec(*args, &self)
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
begin
|
||||
method_from_binding = eval("method(#{method.inspect})", @binding)
|
||||
return method_from_binding.call(*args)
|
||||
rescue NameError
|
||||
# fall through on purpose
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user