Class: TappingDevice

Inherits:
Object
  • Object
show all
Extended by:
Manageable
Includes:
Configurable, Output::Helpers
Defined in:
lib/tapping_device.rb,
lib/tapping_device/output.rb,
lib/tapping_device/payload.rb,
lib/tapping_device/version.rb,
lib/tapping_device/trackable.rb,
lib/tapping_device/exceptions.rb,
lib/tapping_device/manageable.rb,
lib/tapping_device/configurable.rb,
lib/tapping_device/output/writer.rb,
lib/tapping_device/method_hijacker.rb,
lib/tapping_device/output/payload_wrapper.rb,
lib/tapping_device/trackers/passed_tracker.rb,
lib/tapping_device/trackers/mutation_tracker.rb,
lib/tapping_device/trackers/method_call_tracker.rb,
lib/tapping_device/trackers/initialization_tracker.rb,
lib/tapping_device/trackers/association_call_tracker.rb

Defined Under Namespace

Modules: Configurable, Manageable, Output, Trackable, Trackers Classes: Exception, MethodHijacker, NotAClassError, NotAnActiveRecordInstanceError, Payload

Constant Summary collapse

CALLER_START_POINT =
3
C_CALLER_START_POINT =
2
VERSION =
"0.6.0"

Constants included from Configurable

Configurable::DEFAULTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Manageable

delete_device, devices, reset!, stop_all!, suspend_new, suspend_new!

Methods included from Output::Helpers

#and_output, #and_print, #and_write

Constructor Details

#initialize(options = {}, &block) ⇒ TappingDevice

Returns a new instance of TappingDevice.



33
34
35
36
37
38
39
40
41
# File 'lib/tapping_device.rb', line 33

def initialize(options = {}, &block)
  @block = block
  @output_block = nil
  @options = process_options(options.dup)
  @calls = []
  @disabled = false
  @with_condition = nil
  TappingDevice.devices << self
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



23
24
25
# File 'lib/tapping_device.rb', line 23

def calls
  @calls
end

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/tapping_device.rb', line 23

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



23
24
25
# File 'lib/tapping_device.rb', line 23

def target
  @target
end

#trace_pointObject (readonly)

Returns the value of attribute trace_point.



23
24
25
# File 'lib/tapping_device.rb', line 23

def trace_point
  @trace_point
end

Instance Method Details

#create_child_deviceObject



60
61
62
63
64
65
66
# File 'lib/tapping_device.rb', line 60

def create_child_device
  new_device = self.class.new(@options.merge(root_device: root_device), &@block)
  new_device.stop_when(&@stop_when)
  new_device.instance_variable_set(:@target, @target)
  self.descendants << new_device
  new_device
end

#descendantsObject



72
73
74
# File 'lib/tapping_device.rb', line 72

def descendants
  options[:descendants]
end

#root_deviceObject



68
69
70
# File 'lib/tapping_device.rb', line 68

def root_device
  options[:root_device]
end

#set_block(&block) ⇒ Object



47
48
49
# File 'lib/tapping_device.rb', line 47

def set_block(&block)
  @block = block
end

#stop!Object



51
52
53
54
# File 'lib/tapping_device.rb', line 51

def stop!
  @disabled = true
  TappingDevice.delete_device(self)
end

#stop_when(&block) ⇒ Object



56
57
58
# File 'lib/tapping_device.rb', line 56

def stop_when(&block)
  @stop_when = block
end

#track(object) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/tapping_device.rb', line 76

def track(object)
  @target = object
  validate_target!

  MethodHijacker.new(@target).hijack_methods! if options[:hijack_attr_methods]

  @trace_point = build_minimum_trace_point(event_type: options[:event_type]) do |payload|
    record_call!(payload)

    stop_if_condition_fulfilled!(payload)
  end

  @trace_point.enable unless TappingDevice.suspend_new

  self
end

#with(&block) ⇒ Object



43
44
45
# File 'lib/tapping_device.rb', line 43

def with(&block)
  @with_condition = block
end