Class: BugBunny::Resource::ScopeProxy
- Inherits:
- BasicObject
- Defined in:
- lib/bug_bunny/resource.rb
Overview
Proxy para el encadenamiento del método ‘.with`. Solo puede usarse para UNA llamada de método: el contexto se restaura al finalizar.
Configuración de Infraestructura Específica collapse
-
#initialize(target, keys, old_values) ⇒ ScopeProxy
constructor
A new instance of ScopeProxy.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(target, keys, old_values) ⇒ ScopeProxy
Returns a new instance of ScopeProxy.
172 173 174 175 176 177 |
# File 'lib/bug_bunny/resource.rb', line 172 def initialize(target, keys, old_values) @target = target @keys = keys @old_values = old_values @used = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/bug_bunny/resource.rb', line 179 def method_missing(method, *args, &block) ::Kernel.raise ::BugBunny::Error, 'ScopeProxy is single-use. Call .with again for a new context.' if @used @used = true @target.public_send(method, *args, &block) ensure @keys.each { |k, v| ::Thread.current[v] = @old_values[k] } end |