Class: Recruit::Spy
- Inherits:
-
Object
- Object
- Recruit::Spy
- Defined in:
- lib/speq/recruit.rb
Overview
Lets you can keep an eye on your ducks
Instance Method Summary collapse
-
#initialize(proxy_target = nil, permit_all_methods = false) ⇒ Spy
constructor
A new instance of Spy.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name) ⇒ Boolean
Constructor Details
#initialize(proxy_target = nil, permit_all_methods = false) ⇒ Spy
Returns a new instance of Spy.
34 35 36 37 38 |
# File 'lib/speq/recruit.rb', line 34 def initialize(proxy_target = nil, permit_all_methods = false) @report = Hash.new { |hash, key| hash[key] = [] } @proxy_target = proxy_target @permit_all_methods = permit_all_methods end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/speq/recruit.rb', line 44 def method_missing(method_name, *args, &block) @report[method_name] << [args, block] if @proxy_target&.respond_to?(method_name) @proxy_target.send(method_name, *args, &block) else super end rescue NoMethodError => e @permit_all_methods ? nil : e end |
Instance Method Details
#respond_to_missing?(method_name) ⇒ Boolean
40 41 42 |
# File 'lib/speq/recruit.rb', line 40 def respond_to_missing?(method_name, *) permit_all_methods ? true : @proxy_target&.respond_to?(method_name) || super end |