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) ⇒ 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) ⇒ Object
Handles method delegation to the configured objects. Uses argument forwarding to pass all arguments to the delegated method.
23 24 25 26 27 28 29 30 31 |
# File 'lib/workhorse/scoped_env.rb', line 23 def method_missing(symbol, ...) if @methods.include?(symbol) @delegation_object.send(symbol, ...) elsif @backup_binding.try(:respond_to?, symbol) @backup_binding.send(symbol, ...) 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.
38 39 40 |
# File 'lib/workhorse/scoped_env.rb', line 38 def respond_to_missing?(symbol, include_private = false) @methods.include?(symbol) || super end |