watch_point 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/lib/watch_point.rb +63 -0
- data/lib/watch_point/version.rb +3 -0
- data/watch_point.gemspec +25 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Yuen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# WatchPoint
|
2
|
+
|
3
|
+
Stop exactly where a variable gets changed (a.k.a. watchpoints or `trace_var` for all) and help you swim through (other people's) code faster.
|
4
|
+
|
5
|
+
According to [this page](http://www.ruby-doc.org/docs/ProgrammingRuby/html/trouble.html) on ruby-doc.org there used to be watchpoints built into RDebug but I can't seem to find it in 1.9.3 and 2.0.0 on Mac. It turned out to be quite easy to roll your own so here goes.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'watch_point'
|
11
|
+
|
12
|
+
def hello(girl)
|
13
|
+
girl << " Baby"
|
14
|
+
puts "Hello, #{girl}"
|
15
|
+
end
|
16
|
+
|
17
|
+
name = "Mary"
|
18
|
+
|
19
|
+
# Watch any variables!
|
20
|
+
WatchPoint.watch(name)
|
21
|
+
|
22
|
+
WatchPoint.enable
|
23
|
+
|
24
|
+
hello(name)
|
25
|
+
|
26
|
+
WatchPoint.disable
|
27
|
+
```
|
28
|
+
|
29
|
+
You'll get a Pry prompt at the `hello` line:
|
30
|
+
|
31
|
+
From: foo.rb @ line 4 Object#hello:
|
32
|
+
|
33
|
+
3: def hello(girl)
|
34
|
+
=> 4: girl << " Baby"
|
35
|
+
5: puts "Hello, #{girl}"
|
36
|
+
6: end
|
37
|
+
|
38
|
+
[1] pry(main)>
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
Add this line to your application's Gemfile:
|
43
|
+
|
44
|
+
gem 'watch_point'
|
45
|
+
|
46
|
+
And then execute:
|
47
|
+
|
48
|
+
$ bundle
|
49
|
+
|
50
|
+
Or install it yourself as:
|
51
|
+
|
52
|
+
$ gem install watch_point
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/watch_point.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
require 'watch_point/version'
|
4
|
+
|
5
|
+
module WatchPoint
|
6
|
+
@watch_list = []
|
7
|
+
@last_binding = nil
|
8
|
+
|
9
|
+
@interactive_thread = nil
|
10
|
+
@sleeping_threads = []
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def watch(obj)
|
14
|
+
if @watch_list.any? { |obj1, _| obj1.object_id == obj.object_id }
|
15
|
+
raise ArgumentError, "Already watching object ##{obj.object_id}"
|
16
|
+
end
|
17
|
+
|
18
|
+
@watch_list << [obj, obj.hash]
|
19
|
+
@last_binding ||= binding
|
20
|
+
end
|
21
|
+
|
22
|
+
def unwatch(obj)
|
23
|
+
@watch_list.delete_if do |obj1, _|
|
24
|
+
obj.object_id == obj1.object_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def enable
|
29
|
+
set_trace_func(proc do |event, _, _, _, b, _|
|
30
|
+
if @interactive_thread && Thread.current != @interactive_thread
|
31
|
+
@sleeping_threads << Thread.current
|
32
|
+
Thread.stop
|
33
|
+
end
|
34
|
+
|
35
|
+
next if event != 'line'
|
36
|
+
|
37
|
+
@watch_list.each do |obj, hash0|
|
38
|
+
if obj.hash != hash0
|
39
|
+
self.unwatch(obj)
|
40
|
+
|
41
|
+
@interactive_thread = Thread.current
|
42
|
+
# puts "Object #{obj} changed!"
|
43
|
+
@last_binding.pry
|
44
|
+
|
45
|
+
@interactive_thread = nil
|
46
|
+
@sleeping_threads.each(&:wakeup)
|
47
|
+
@sleeping_threads = []
|
48
|
+
|
49
|
+
self.watch(obj)
|
50
|
+
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
@last_binding = b
|
56
|
+
end)
|
57
|
+
end
|
58
|
+
|
59
|
+
def disable
|
60
|
+
set_trace_func(nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/watch_point.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'watch_point/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "watch_point"
|
8
|
+
spec.version = WatchPoint::VERSION
|
9
|
+
spec.authors = ["Chris Yuen"]
|
10
|
+
spec.email = ["chris@kizzx2.com"]
|
11
|
+
spec.description = %q{Lightweight watchpoint implementation}
|
12
|
+
spec.summary = %q{Lightweight watchpoint implementation}
|
13
|
+
spec.homepage = "https://github.com/kizzx2/watch_point"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'pry', '>= 0.9.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watch_point
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Yuen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.0
|
62
|
+
description: Lightweight watchpoint implementation
|
63
|
+
email:
|
64
|
+
- chris@kizzx2.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/watch_point.rb
|
75
|
+
- lib/watch_point/version.rb
|
76
|
+
- watch_point.gemspec
|
77
|
+
homepage: https://github.com/kizzx2/watch_point
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 2426669687230727655
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: 2426669687230727655
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.23
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Lightweight watchpoint implementation
|
108
|
+
test_files: []
|