Class: TappingDevice

Inherits:
Object
  • Object
show all
Extended by:
Manageable
Includes:
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/configuration.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: Manageable, Output, Trackable, Trackers Classes: Configuration, Exception, MethodHijacker, NotAClassError, NotAnActiveRecordInstanceError, Payload

Constant Summary collapse

CALLER_START_POINT =
3
C_CALLER_START_POINT =
2
VERSION =
"0.6.1"

Instance Attribute Summary collapse

Class Method 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.



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

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.



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

def calls
  @calls
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

#trace_pointObject (readonly)

Returns the value of attribute trace_point.



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

def trace_point
  @trace_point
end

Class Method Details

.configObject



31
32
33
# File 'lib/tapping_device/configuration.rb', line 31

def self.config
  @config ||= Configuration.new
end

Instance Method Details

#create_child_deviceObject



58
59
60
61
62
63
64
# File 'lib/tapping_device.rb', line 58

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



70
71
72
# File 'lib/tapping_device.rb', line 70

def descendants
  options[:descendants]
end

#root_deviceObject



66
67
68
# File 'lib/tapping_device.rb', line 66

def root_device
  options[:root_device]
end

#set_block(&block) ⇒ Object



45
46
47
# File 'lib/tapping_device.rb', line 45

def set_block(&block)
  @block = block
end

#stop!Object



49
50
51
52
# File 'lib/tapping_device.rb', line 49

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

#stop_when(&block) ⇒ Object



54
55
56
# File 'lib/tapping_device.rb', line 54

def stop_when(&block)
  @stop_when = block
end

#track(object) ⇒ Object



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

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



41
42
43
# File 'lib/tapping_device.rb', line 41

def with(&block)
  @with_condition = block
end