class Crispy::CrispyInternal::Spy

Attributes

received_messages[R]

Public Class Methods

new(target, except: []) click to toggle source
Calls superclass method
# File lib/crispy/crispy_internal/spy.rb, line 14
def initialize target, except: []
  spy = self
  module_eval do
    define_method(:__CRISPY_SPY__) { spy }
  end

  @received_messages = []
  super

  self.class.remember_to_reset_later self
end
of_target(target) click to toggle source
# File lib/crispy/crispy_internal/spy.rb, line 36
def self.of_target target
  (defined? target.__CRISPY_SPY__) && target.__CRISPY_SPY__
end
remember_to_reset_later(spy) click to toggle source
# File lib/crispy/crispy_internal/spy.rb, line 46
def self.remember_to_reset_later spy
  @spies_to_reset << ::WeakRef.new(spy)
end
reset_all() click to toggle source
# File lib/crispy/crispy_internal/spy.rb, line 50
def self.reset_all
  # get rid of spies of GCed objects
  @spies_to_reset.select! do|spy|
    if alive = spy.weakref_alive?
      spy.reinitialize
    end
    alive
  end
end

Public Instance Methods

erase_log() click to toggle source
# File lib/crispy/crispy_internal/spy.rb, line 32
def erase_log
  @received_messages.clear
end
target_to_class(target) click to toggle source
# File lib/crispy/crispy_internal/spy.rb, line 26
def target_to_class target
  class << target
    self
  end
end

Private Instance Methods

append_received_message(receiver, method_name, *arguments, &attached_block) click to toggle source
# File lib/crispy/crispy_internal/spy.rb, line 40
def append_received_message receiver, method_name, *arguments, &attached_block
  @received_messages <<
    ::Crispy::CrispyReceivedMessage.new(method_name, *arguments, &attached_block)
end