Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #81 from st0012/rename-to-object-tracer
Browse files Browse the repository at this point in the history
Rename the project to ObjectTracer
  • Loading branch information
st0012 committed May 22, 2021
2 parents eaaec9a + b5dedb3 commit 4ac0f98
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 130 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source "https://rubygems.org"

# Specify your gem's dependencies in tapping_device.gemspec
gemspec

rails_version = ENV["RAILS_VERSION"]
Expand Down
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# TappingDevice
# ObjectTracer (previously called TappingDevice)

![GitHub Action](https://github.com/st0012/tapping_device/workflows/Ruby/badge.svg)
[![Gem Version](https://badge.fury.io/rb/tapping_device.svg)](https://badge.fury.io/rb/tapping_device)
[![Maintainability](https://api.codeclimate.com/v1/badges/3e3732a6983785bccdbd/maintainability)](https://codeclimate.com/github/st0012/tapping_device/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/3e3732a6983785bccdbd/test_coverage)](https://codeclimate.com/github/st0012/tapping_device/test_coverage)
[![Open Source Helpers](https://www.codetriage.com/st0012/tapping_device/badges/users.svg)](https://www.codetriage.com/st0012/tapping_device)
![GitHub Action](https://github.com/st0012/object_tracer/workflows/Ruby/badge.svg)
[![Gem Version](https://badge.fury.io/rb/object_tracer.svg)](https://badge.fury.io/rb/object_tracer)
[![Maintainability](https://api.codeclimate.com/v1/badges/3e3732a6983785bccdbd/maintainability)](https://codeclimate.com/github/st0012/object_tracer/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/3e3732a6983785bccdbd/test_coverage)](https://codeclimate.com/github/st0012/object_tracer/test_coverage)
[![Open Source Helpers](https://www.codetriage.com/st0012/object_tracer/badges/users.svg)](https://www.codetriage.com/st0012/object_tracer)


## Introduction
As the name states, `TappingDevice` allows you to secretly listen to different events of an object:
As the name states, `ObjectTracer` allows you to secretly listen to different events of an object:

- `Method Calls` - what does the object do
- `Traces` - how is the object used by the application
- `State Mutations` - what happens inside the object

After collecting the events, `TappingDevice` will output them in a nice, readable format to either stdout or a file.
After collecting the events, `ObjectTracer` will output them in a nice, readable format to either stdout or a file.

**Ultimately, its goal is to let you know all the information you need for debugging with just 1 line of code.**

Expand All @@ -24,7 +24,7 @@ After collecting the events, `TappingDevice` will output them in a nice, readabl

By tracking an object's method calls, you'll be able to observe the object's behavior very easily

<img src="https://github.com/st0012/tapping_device/blob/master/images/print_calls.png" alt="image of print_calls output" width="50%">
<img src="https://github.com/st0012/object_tracer/blob/master/images/print_calls.png" alt="image of print_calls output" width="50%">

Each entry consists of 5 pieces of information:
- method name
Expand All @@ -33,13 +33,13 @@ Each entry consists of 5 pieces of information:
- arguments
- return value

![explanation of individual entry](https://github.com/st0012/tapping_device/blob/master/images/print_calls%20-%20single%20entry.png)
![explanation of individual entry](https://github.com/st0012/object_tracer/blob/master/images/print_calls%20-%20single%20entry.png)

#### Helpers

- `print_calls(object)` - prints the result to stdout
- `write_calls(object, log_file: "file_name")` - writes the result to a file
- the default file is `/tmp/tapping_device.log`, but you can change it with `log_file: "new_path"` option
- the default file is `/tmp/object_tracer.log`, but you can change it with `log_file: "new_path"` option

#### Use Cases
- Understand a service object/form object's behavior
Expand All @@ -49,13 +49,13 @@ Each entry consists of 5 pieces of information:

By tracking an object's traces, you'll be able to observe the object's journey in your application

![image of print_traces output](https://github.com/st0012/tapping_device/blob/master/images/print_traces.png)
![image of print_traces output](https://github.com/st0012/object_tracer/blob/master/images/print_traces.png)

#### Helpers

- `print_traces(object)` - prints the result to stdout
- `write_traces(object, log_file: "file_name")` - writes the result to a file
- the default file is `/tmp/tapping_device.log`, but you can change it with `log_file: "new_path"` option
- the default file is `/tmp/object_tracer.log`, but you can change it with `log_file: "new_path"` option

#### Use Cases
- Debug argument related issues
Expand All @@ -65,13 +65,13 @@ By tracking an object's traces, you'll be able to observe the object's journey i

By tracking an object's traces, you'll be able to observe the state changes happen inside the object between each method call

<img src="https://github.com/st0012/tapping_device/blob/master/images/print_mutations.png" alt="image of print_mutations output" width="50%">
<img src="https://github.com/st0012/object_tracer/blob/master/images/print_mutations.png" alt="image of print_mutations output" width="50%">

#### Helpers

- `print_mutations(object)` - prints the result to stdout
- `write_mutations(object, log_file: "file_name")` - writes the result to a file
- the default file is `/tmp/tapping_device.log`, but you can change it with `log_file: "new_path"` option
- the default file is `/tmp/object_tracer.log`, but you can change it with `log_file: "new_path"` option

#### Use Cases
- Debug state related issues
Expand Down Expand Up @@ -105,7 +105,7 @@ print_calls(service, options)
service.perform
```

This kind of code changes are usually annoying, and that's one of the problems I want to solve with `TappingDevice`.
This kind of code changes are usually annoying, and that's one of the problems I want to solve with `ObjectTracer`.

So here's another option, just insert a `with_HELPER_NAME` call in between:

Expand All @@ -125,7 +125,7 @@ service.perform
Add this line to your application's Gemfile:

```ruby
gem 'tapping_device', group: :development
gem 'object_tracer', group: :development
```

And then execute:
Expand All @@ -137,10 +137,10 @@ $ bundle
Or install it directly:

```
$ gem install tapping_device
$ gem install object_tracer
```

**Depending on the size of your application, `TappingDevice` could harm the performance significantly. So make sure you don't put it inside the production group**
**Depending on the size of your application, `ObjectTracer` could harm the performance significantly. So make sure you don't put it inside the production group**


## Advance Usages & Options
Expand All @@ -161,7 +161,7 @@ end
There are many options you can pass when using a helper method. You can list all available options and their default value with

```ruby
TappingDevice::Configurable::DEFAULTS #=> {
ObjectTracer::Configurable::DEFAULTS #=> {
:filter_by_paths=>[],
:exclude_by_paths=>[],
:with_trace_to=>50,
Expand All @@ -170,7 +170,7 @@ TappingDevice::Configurable::DEFAULTS #=> {
:track_as_records=>false,
:inspect=>false,
:colorize=>true,
:log_file=>"/tmp/tapping_device.log"
:log_file=>"/tmp/object_tracer.log"
}
```

Expand Down Expand Up @@ -267,27 +267,27 @@ This option does the opposite of the `ignore_private` option does.
If you don't want to pass options every time you use a helper, you can use global configuration to change the default values:

```ruby
TappingDevice.config[:colorize] = false
TappingDevice.config[:hijack_attr_methods] = true
ObjectTracer.config[:colorize] = false
ObjectTracer.config[:hijack_attr_methods] = true
```

And if you're using Rails, you can put the configs under `config/initializers/tapping_device.rb` like this:
And if you're using Rails, you can put the configs under `config/initializers/object_tracer.rb` like this:

```ruby
if defined?(TappingDevice)
TappingDevice.config[:colorize] = false
TappingDevice.config[:hijack_attr_methods] = true
if defined?(ObjectTracer)
ObjectTracer.config[:colorize] = false
ObjectTracer.config[:hijack_attr_methods] = true
end
```


### Lower-Level Helpers
`print_calls` and `print_traces` aren't the only helpers you can get from `TappingDevice`. They are actually built on top of other helpers, which you can use as well. To know more about them, please check [this page](https://github.com/st0012/tapping_device/wiki/Advance-Usages)
`print_calls` and `print_traces` aren't the only helpers you can get from `ObjectTracer`. They are actually built on top of other helpers, which you can use as well. To know more about them, please check [this page](https://github.com/st0012/object_tracer/wiki/Advance-Usages)


### Related Blog Posts
- [Optimize Your Debugging Process With Object-Oriented Tracing and tapping_device](http://bit.ly/object-oriented-tracing)
- [Debug Rails issues effectively with tapping_device](https://dev.to/st0012/debug-rails-issues-effectively-with-tappingdevice-c7c)
- [Optimize Your Debugging Process With Object-Oriented Tracing and object_tracer](http://bit.ly/object-oriented-tracing)
- [Debug Rails issues effectively with object_tracer](https://dev.to/st0012/debug-rails-issues-effectively-with-tappingdevice-c7c)
- [Want to know more about your Rails app? Tap on your objects!](https://dev.to/st0012/want-to-know-more-about-your-rails-app-tap-on-your-objects-bd3)


Expand All @@ -298,13 +298,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/st0012/tapping_device. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
Bug reports and pull requests are welcome on GitHub at https://github.com/st0012/object_tracer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

## License

The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the TappingDevice project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tapping_device/blob/master/CODE_OF_CONDUCT.md).
Everyone interacting in the ObjectTracer project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/st0012/object_tracer/blob/master/CODE_OF_CONDUCT.md).

2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "tapping_device"
require "object_tracer"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
48 changes: 24 additions & 24 deletions lib/tapping_device.rb → lib/object_tracer.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require "method_source" # for using Method#source

require "tapping_device/version"
require "tapping_device/manageable"
require "tapping_device/payload"
require "tapping_device/output"
require "tapping_device/trackable"
require "tapping_device/configuration"
require "tapping_device/exceptions"
require "tapping_device/method_hijacker"
require "tapping_device/trackers/initialization_tracker"
require "tapping_device/trackers/passed_tracker"
require "tapping_device/trackers/association_call_tracker"
require "tapping_device/trackers/method_call_tracker"
require "tapping_device/trackers/mutation_tracker"

class TappingDevice
require "object_tracer/version"
require "object_tracer/manageable"
require "object_tracer/payload"
require "object_tracer/output"
require "object_tracer/trackable"
require "object_tracer/configuration"
require "object_tracer/exceptions"
require "object_tracer/method_hijacker"
require "object_tracer/trackers/initialization_tracker"
require "object_tracer/trackers/passed_tracker"
require "object_tracer/trackers/association_call_tracker"
require "object_tracer/trackers/method_call_tracker"
require "object_tracer/trackers/mutation_tracker"

class ObjectTracer

CALLER_START_POINT = 3
C_CALLER_START_POINT = 2
Expand All @@ -35,7 +35,7 @@ def initialize(options = {}, &block)
@calls = []
@disabled = false
@with_condition = nil
TappingDevice.devices << self
ObjectTracer.devices << self
end

def with(&block)
Expand All @@ -48,7 +48,7 @@ def set_block(&block)

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

def stop_when(&block)
Expand Down Expand Up @@ -83,7 +83,7 @@ def track(object)
stop_if_condition_fulfilled!(payload)
end

@trace_point.enable unless TappingDevice.suspend_new
@trace_point.enable unless ObjectTracer.suspend_new

self
end
Expand All @@ -98,7 +98,7 @@ def build_minimum_trace_point(event_type:)
payload = build_payload(tp: tp, filepath: filepath, line_number: line_number)

unless @options[:force_recording]
next if is_tapping_device_call?(tp)
next if is_object_tracer_call?(tp)
next if should_be_skipped_by_paths?(filepath)
next unless with_condition_satisfied?(payload)
next if payload.is_private_call? && @options[:ignore_private]
Expand All @@ -123,15 +123,15 @@ def should_be_skipped_by_paths?(filepath)
(filter_by_paths && !filter_by_paths.empty? && !filter_by_paths.any? { |pattern| pattern.match?(filepath) })
end

def is_tapping_device_call?(tp)
if tp.defined_class == TappingDevice::Trackable || tp.defined_class == TappingDevice
def is_object_tracer_call?(tp)
if tp.defined_class == ObjectTracer::Trackable || tp.defined_class == ObjectTracer
return true
end

if Module.respond_to?(:module_parents)
tp.defined_class.module_parents.include?(TappingDevice)
tp.defined_class.module_parents.include?(ObjectTracer)
elsif Module.respond_to?(:parents)
tp.defined_class.parents.include?(TappingDevice)
tp.defined_class.parents.include?(ObjectTracer)
end
end

Expand Down Expand Up @@ -253,6 +253,6 @@ def stop_if_condition_fulfilled!(payload)
end

def config
TappingDevice.config
ObjectTracer.config
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TappingDevice
class ObjectTracer
class Configuration
DEFAULTS = {
filter_by_paths: [],
Expand All @@ -9,7 +9,7 @@ class Configuration
track_as_records: false,
ignore_private: false,
only_private: false
}.merge(TappingDevice::Output::DEFAULT_OPTIONS)
}.merge(ObjectTracer::Output::DEFAULT_OPTIONS)

def initialize
@options = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TappingDevice
class ObjectTracer
class Exception < StandardError
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TappingDevice
class ObjectTracer
module Manageable

def suspend_new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TappingDevice
class ObjectTracer
class MethodHijacker
attr_reader :target

Expand Down
8 changes: 4 additions & 4 deletions lib/tapping_device/output.rb → lib/object_tracer/output.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require "logger"
require "tapping_device/output/payload_wrapper"
require "tapping_device/output/writer"
require "object_tracer/output/payload_wrapper"
require "object_tracer/output/writer"

class TappingDevice
class ObjectTracer
module Output
DEFAULT_OPTIONS = {
inspect: false,
colorize: true,
log_file: "/tmp/tapping_device.log"
log_file: "/tmp/object_tracer.log"
}

module Helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "pastel"

class TappingDevice
class ObjectTracer
module Output
class PayloadWrapper
UNDEFINED = "[undefined]"
Expand All @@ -9,7 +9,7 @@ class PayloadWrapper
PASTEL = Pastel.new
PASTEL.alias_color(:orange, :bright_red, :bright_yellow)

TappingDevice::Payload::ATTRS.each do |attr|
ObjectTracer::Payload::ATTRS.each do |attr|
define_method attr do |options = {}|
@payload.send(attr)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TappingDevice
class ObjectTracer
module Output
class Writer
def initialize(options:, output_block:, logger:)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TappingDevice
class ObjectTracer
class Payload
ATTRS = [
:target, :receiver, :method_name, :method_object, :arguments, :return_value, :filepath, :line_number,
Expand Down
Loading

0 comments on commit 4ac0f98

Please sign in to comment.