pry-nav 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-nav.gemspec
4
+ gemspec
@@ -0,0 +1,29 @@
1
+ pry-nav
2
+ =======
3
+
4
+ _Simple execution control in Pry_
5
+
6
+ Adds **step** and **next** commands to your [Pry][pry]
7
+ console. Makes for a simple but ghetto debugger.
8
+
9
+ Note: In order to get the correct flow control, `Pry.start` is overriden. Use at
10
+ your own risk.
11
+
12
+
13
+ ## Acknowledgments
14
+
15
+ - Ruby stdlib [debug.rb][debug.rb]
16
+ - [@Mon-Ouie][Mon-Ouie]'s [pry_debug][pry_debug]
17
+
18
+
19
+ ## TODO
20
+
21
+ - Thread safety
22
+ - Compatibility with [pry-remote][pry-remote]
23
+
24
+
25
+ [pry]: http://pry.github.com
26
+ [debug.rb]: https://github.com/ruby/ruby/blob/trunk/lib/debug.rb
27
+ [Mon-Ouie]: https://github.com/Mon-Ouie
28
+ [pry_debug]: https://github.com/Mon-Ouie/pry_debug
29
+ [pry-remote]: https://github.com/Mon-Ouie/pry-remote
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ require 'pry-nav/version'
2
+ require 'pry-nav/pry_ext'
3
+ require 'pry-nav/commands'
4
+ require 'pry-nav/tracer'
@@ -0,0 +1,28 @@
1
+ require 'pry'
2
+
3
+ module PryNav
4
+ Commands = Pry::CommandSet.new do
5
+ command 'step', 'Step execution into the next line or method.' do |steps|
6
+ breakout_navigation :step, steps
7
+ end
8
+
9
+ command 'next', 'Execute the next line within the same stack frame.' do |lines|
10
+ breakout_navigation :next, lines
11
+ end
12
+
13
+ alias_command 'n', 'next'
14
+ alias_command 's', 'step'
15
+
16
+ helpers do
17
+ def breakout_navigation(action, times)
18
+ _pry_.binding_stack.clear # Clear the binding stack.
19
+ throw :breakout_nav, { # Break out of the REPL loop and
20
+ action: action, # signal the tracer.
21
+ times: times
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ Pry.commands.import PryNav::Commands
@@ -0,0 +1,11 @@
1
+ require 'pry'
2
+
3
+ class << Pry
4
+ alias_method :start_existing, :start
5
+
6
+ def start(target = TOPLEVEL_BINDING, options = {})
7
+ PryNav::Tracer.new(options) do
8
+ start_existing(target, options)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,85 @@
1
+ require 'pry'
2
+
3
+ module PryNav
4
+ class Tracer
5
+ FILE = File.expand_path(__FILE__)
6
+
7
+ def initialize(pry_start_options = {}, &block)
8
+ @step_in_lines = -1 # Break after this many lines
9
+ @frames_when_stepping = nil # Only break at this frame level
10
+ @frames = [] # Traced stack frames
11
+ @pry_start_options = pry_start_options # Options to use for Pry.start
12
+
13
+ run &block
14
+ end
15
+
16
+ def run(&block)
17
+ start # Set the trace function
18
+
19
+ return_value = nil
20
+ command = catch(:breakout_nav) do # Coordinate with PryNav::Commands
21
+ return_value = yield
22
+ {} # Nothing thrown == no navigational command
23
+ end
24
+
25
+ process_command command
26
+
27
+ return_value
28
+ end
29
+
30
+ def start
31
+ set_trace_func method(:tracer).to_proc
32
+ end
33
+
34
+ def stop
35
+ set_trace_func nil
36
+ end
37
+
38
+ def process_command(command = {})
39
+ times = (command[:times] || 1).to_i
40
+ times = 1 if times <= 0
41
+
42
+ case command[:action]
43
+ when :step
44
+ @step_in_lines = times
45
+ @frames_when_stepping = nil
46
+ when :next
47
+ @step_in_lines = times
48
+ @frames_when_stepping = @frames.size
49
+ else
50
+ stop
51
+ end
52
+ end
53
+
54
+
55
+ private
56
+
57
+ def tracer(event, file, line, id, binding, klass)
58
+ # Ignore traces inside pry-nav code
59
+ return if (file && File.expand_path(file) == FILE)
60
+
61
+ case event
62
+ when 'line'
63
+ # Are we stepping? Or continuing by line ('next') and we're at the right
64
+ # frame? Then decrement our line counter cause this line counts.
65
+ if !@frames_when_stepping || @frames.size == @frames_when_stepping
66
+ @step_in_lines -= 1
67
+ @step_in_lines = -1 if @step_in_lines < 0
68
+
69
+ # Did we go up a frame and not break for a 'next' yet?
70
+ elsif @frames.size < @frames_when_stepping
71
+ @step_in_lines = 0 # Break right away
72
+ end
73
+
74
+ # Break on this line?
75
+ Pry.start(binding, @pry_start_options) if @step_in_lines == 0
76
+
77
+ when 'call', 'class'
78
+ @frames.unshift [binding, file, line, id] # Track entering a frame
79
+
80
+ when 'return', 'end'
81
+ @frames.shift # Track leaving a stack frame
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module PryNav
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/pry-nav/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'pry-nav'
7
+ gem.version = PryNav::VERSION
8
+ gem.author = 'Gopal Patel'
9
+ gem.email = 'nixme@stillhope.com'
10
+ gem.license = 'MIT'
11
+ gem.homepage = 'https://github.com/nixme/pry-nav'
12
+ gem.summary = 'Simple execution navigation for Pry.'
13
+ gem.description = "Turn Pry into a primitive debugger. Adds 'step' and 'next' commands to control execution."
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.require_paths = ["lib"]
19
+
20
+ # Dependencies
21
+ gem.required_ruby_version = '>= 1.9.2'
22
+ gem.add_runtime_dependency 'pry', '~> 0.9.7.4'
23
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-nav
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gopal Patel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: &70106424403940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.7.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70106424403940
25
+ description: Turn Pry into a primitive debugger. Adds 'step' and 'next' commands to
26
+ control execution.
27
+ email: nixme@stillhope.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/pry-nav.rb
37
+ - lib/pry-nav/commands.rb
38
+ - lib/pry-nav/pry_ext.rb
39
+ - lib/pry-nav/tracer.rb
40
+ - lib/pry-nav/version.rb
41
+ - pry-nav.gemspec
42
+ homepage: https://github.com/nixme/pry-nav
43
+ licenses:
44
+ - MIT
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.2
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.11
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Simple execution navigation for Pry.
67
+ test_files: []
68
+ has_rdoc: