Class: Impersonator::Proxy
- Inherits:
-
Object
- Object
- Impersonator::Proxy
- Includes:
- HasLogger
- Defined in:
- lib/impersonator/proxy.rb
Overview
A proxy represents the impersonated object at both record and replay times.
For not impersonated methods, it will just delegate to the impersonate object. For impersonated methods, it will interact with the recording for recording or replaying the object interactions.
Instance Attribute Summary collapse
-
#impersonated_object ⇒ Object
readonly
Returns the value of attribute impersonated_object.
Instance Method Summary collapse
-
#configure_method_matching_for(method) {|config| ... } ⇒ Object
Configure matching options for a given method.
-
#initialize(impersonated_object, recording:, impersonated_methods:) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, *args) ⇒ Boolean
Methods included from HasLogger
Constructor Details
#initialize(impersonated_object, recording:, impersonated_methods:) ⇒ Proxy
Returns a new instance of Proxy.
15 16 17 18 19 20 21 22 |
# File 'lib/impersonator/proxy.rb', line 15 def initialize(impersonated_object, recording:, impersonated_methods:) validate_object_has_methods_to_impersonate!(impersonated_object, impersonated_methods) @impersonated_object = impersonated_object @impersonated_methods = impersonated_methods.collect(&:to_sym) @recording = recording @method_matching_configurations_by_method = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/impersonator/proxy.rb', line 24 def method_missing(method_name, *args, &block) if @impersonated_methods.include?(method_name.to_sym) invoke_impersonated_method(method_name, *args, &block) else @impersonated_object.send(method_name, *args, &block) end end |
Instance Attribute Details
#impersonated_object ⇒ Object (readonly)
Returns the value of attribute impersonated_object.
10 11 12 |
# File 'lib/impersonator/proxy.rb', line 10 def impersonated_object @impersonated_object end |
Instance Method Details
#configure_method_matching_for(method) {|config| ... } ⇒ Object
Configure matching options for a given method
impersonator.configure_method_matching_for(:add) do |config|
config.ignore_arguments_at 0
end
46 47 48 49 |
# File 'lib/impersonator/proxy.rb', line 46 def configure_method_matching_for(method) method_matching_configurations_by_method[method.to_sym] ||= MethodMatchingConfiguration.new yield method_matching_configurations_by_method[method] end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
32 33 34 |
# File 'lib/impersonator/proxy.rb', line 32 def respond_to_missing?(method_name, *args) impersonated_object.respond_to_missing?(method_name, *args) end |