Module: Spy::Instance::Strategy

Defined in:
lib/spy/instance/strategy.rb,
lib/spy/instance/strategy/wrap.rb,
lib/spy/instance/strategy/intercept.rb

Defined Under Namespace

Classes: Intercept, Wrap

Class Method Summary collapse

Class Method Details

.factory_build(spy) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/spy/instance/strategy.rb', line 8

def factory_build(spy)
  if spy.original.is_a?(Method)
    if spy.original.owner == spy.spied.singleton_class
      Strategy::Wrap.new(spy)
    else
      Strategy::Intercept.new(spy, spy.spied.singleton_class)
    end
  else
    if spy.original.owner == spy.spied
      Strategy::Wrap.new(spy)
    else
      Strategy::Intercept.new(spy, spy.spied)
    end
  end
end