Class: Spy::Instance
- Inherits:
-
Object
- Object
- Spy::Instance
- Defined in:
- lib/spy/instance.rb,
lib/spy/instance/strategy.rb,
lib/spy/instance/strategy/wrap.rb,
lib/spy/instance/strategy/intercept.rb
Defined Under Namespace
Modules: Strategy
Instance Attribute Summary collapse
-
#call_count ⇒ Object
readonly
Returns the value of attribute call_count.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#spied ⇒ Object
readonly
Returns the value of attribute spied.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Instance Method Summary collapse
- #before_call(*args) ⇒ Object
-
#initialize(spied, original) ⇒ Instance
constructor
A new instance of Instance.
- #start ⇒ Object
- #stop ⇒ Object
- #when(&block) ⇒ Object
- #with_args(*args) ⇒ Object
Constructor Details
#initialize(spied, original) ⇒ Instance
Returns a new instance of Instance.
13 14 15 16 17 18 19 20 |
# File 'lib/spy/instance.rb', line 13 def initialize(spied, original) @spied = spied @original = original @visibility = extract_visibility @before_filters = [] @call_count = 0 @strategy = Strategy.factory_build(self) end |
Instance Attribute Details
#call_count ⇒ Object (readonly)
Returns the value of attribute call_count.
11 12 13 |
# File 'lib/spy/instance.rb', line 11 def call_count @call_count end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
11 12 13 |
# File 'lib/spy/instance.rb', line 11 def original @original end |
#spied ⇒ Object (readonly)
Returns the value of attribute spied.
11 12 13 |
# File 'lib/spy/instance.rb', line 11 def spied @spied end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
11 12 13 |
# File 'lib/spy/instance.rb', line 11 def strategy @strategy end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
11 12 13 |
# File 'lib/spy/instance.rb', line 11 def visibility @visibility end |
Instance Method Details
#before_call(*args) ⇒ Object
32 33 34 |
# File 'lib/spy/instance.rb', line 32 def before_call(*args) @call_count += 1 if @before_filters.all? {|f| f.before_call(*args)} end |
#start ⇒ Object
22 23 24 25 |
# File 'lib/spy/instance.rb', line 22 def start @strategy.apply self end |
#stop ⇒ Object
27 28 29 30 |
# File 'lib/spy/instance.rb', line 27 def stop @strategy.undo self end |
#when(&block) ⇒ Object
40 41 42 |
# File 'lib/spy/instance.rb', line 40 def when(&block) add_before_filter Callbacks::When.new(block) end |
#with_args(*args) ⇒ Object
36 37 38 |
# File 'lib/spy/instance.rb', line 36 def with_args(*args) add_before_filter Callbacks::WithArgs.new(*args) end |