Class: Workhorse::ScopedEnv
- Inherits:
-
Object
- Object
- Workhorse::ScopedEnv
- Defined in:
- lib/workhorse/scoped_env.rb
Overview
Scoped environment for method delegation. Used internally to provide scoped access to daemon configuration methods.
Instance Method Summary collapse
-
#initialize(delegation_object, methods, backup_binding = nil) ⇒ ScopedEnv
constructor
Creates a new scoped environment.
-
#method_missing(symbol, *args, &block) ⇒ Object
Handles method delegation to the configured objects.
-
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Checks if this object can respond to the given method.
Constructor Details
#initialize(delegation_object, methods, backup_binding = nil) ⇒ ScopedEnv
Creates a new scoped environment.
12 13 14 15 16 |
# File 'lib/workhorse/scoped_env.rb', line 12 def initialize(delegation_object, methods, backup_binding = nil) @delegation_object = delegation_object @methods = methods @backup_binding = backup_binding end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
Handles method delegation to the configured objects.
24 25 26 27 28 29 30 31 32 |
# File 'lib/workhorse/scoped_env.rb', line 24 def method_missing(symbol, *args, &block) if @methods.include?(symbol) @delegation_object.send(symbol, *args, &block) elsif @backup_binding.try(:respond_to?, symbol) @backup_binding.send(symbol, *args, &block) else super end end |
Instance Method Details
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Checks if this object can respond to the given method.
39 40 41 |
# File 'lib/workhorse/scoped_env.rb', line 39 def respond_to_missing?(symbol, include_private = false) @methods.include?(symbol) || super end |