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.

Since:

  • 3.1.2

Configuración de Infraestructura Específica collapse

Constructor Details

#initialize(target, keys, old_values) ⇒ ScopeProxy

Returns a new instance of ScopeProxy.

Since:

  • 3.1.2



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

Since:

  • 3.1.2



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