Class: ObjectTracer
- Inherits:
-
Object
- Object
- ObjectTracer
- Extended by:
- Manageable
- Includes:
- Output::Helpers
- Defined in:
- lib/object_tracer.rb,
lib/object_tracer/output.rb,
lib/object_tracer/payload.rb,
lib/object_tracer/version.rb,
lib/object_tracer/trackable.rb,
lib/object_tracer/exceptions.rb,
lib/object_tracer/manageable.rb,
lib/object_tracer/configuration.rb,
lib/object_tracer/output/writer.rb,
lib/object_tracer/method_hijacker.rb,
lib/object_tracer/output/payload_wrapper.rb,
lib/object_tracer/trackers/passed_tracker.rb,
lib/object_tracer/trackers/mutation_tracker.rb,
lib/object_tracer/trackers/method_call_tracker.rb,
lib/object_tracer/trackers/initialization_tracker.rb,
lib/object_tracer/trackers/association_call_tracker.rb
Direct Known Subclasses
Trackers::AssociactionCallTracker, Trackers::InitializationTracker, Trackers::MethodCallTracker, Trackers::MutationTracker, Trackers::PassedTracker
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 =
"1.0.0"
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#trace_point ⇒ Object
readonly
Returns the value of attribute trace_point.
Class Method Summary collapse
Instance Method Summary collapse
- #create_child_device ⇒ Object
- #descendants ⇒ Object
-
#initialize(options = {}, &block) ⇒ ObjectTracer
constructor
A new instance of ObjectTracer.
- #root_device ⇒ Object
- #set_block(&block) ⇒ Object
- #stop! ⇒ Object
- #stop_when(&block) ⇒ Object
- #track(object) ⇒ Object
- #with(&block) ⇒ Object
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) ⇒ ObjectTracer
Returns a new instance of ObjectTracer.
31 32 33 34 35 36 37 38 39 |
# File 'lib/object_tracer.rb', line 31 def initialize( = {}, &block) @block = block @output_block = nil @options = (.dup) @calls = [] @disabled = false @with_condition = nil ObjectTracer.devices << self end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
22 23 24 |
# File 'lib/object_tracer.rb', line 22 def calls @calls end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/object_tracer.rb', line 22 def @options end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
22 23 24 |
# File 'lib/object_tracer.rb', line 22 def target @target end |
#trace_point ⇒ Object (readonly)
Returns the value of attribute trace_point.
22 23 24 |
# File 'lib/object_tracer.rb', line 22 def trace_point @trace_point end |
Class Method Details
.config ⇒ Object
31 32 33 |
# File 'lib/object_tracer/configuration.rb', line 31 def self.config @config ||= Configuration.new end |
Instance Method Details
#create_child_device ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/object_tracer.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 |
#descendants ⇒ Object
70 71 72 |
# File 'lib/object_tracer.rb', line 70 def descendants [:descendants] end |
#root_device ⇒ Object
66 67 68 |
# File 'lib/object_tracer.rb', line 66 def root_device [:root_device] end |
#set_block(&block) ⇒ Object
45 46 47 |
# File 'lib/object_tracer.rb', line 45 def set_block(&block) @block = block end |
#stop! ⇒ Object
49 50 51 52 |
# File 'lib/object_tracer.rb', line 49 def stop! @disabled = true ObjectTracer.delete_device(self) end |
#stop_when(&block) ⇒ Object
54 55 56 |
# File 'lib/object_tracer.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/object_tracer.rb', line 74 def track(object) @target = object validate_target! MethodHijacker.new(@target).hijack_methods! if [:hijack_attr_methods] @trace_point = build_minimum_trace_point(event_type: [:event_type]) do |payload| record_call!(payload) stop_if_condition_fulfilled!(payload) end @trace_point.enable unless ObjectTracer.suspend_new self end |
#with(&block) ⇒ Object
41 42 43 |
# File 'lib/object_tracer.rb', line 41 def with(&block) @with_condition = block end |