pry-stack_explorer 0.2.9pre3 → 0.2.9pre4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,53 +1,114 @@
1
1
  require 'pry'
2
2
 
3
3
  module PryStackExplorer
4
- Commands = Pry::CommandSet.new do
5
- command "up", "Go up to the caller's context. Accepts optional numeric parameter for how many frames to move up." do |inc_str|
6
- inc = inc_str.nil? ? 1 : inc_str.to_i
4
+ module FrameHelpers
5
+ private
6
+ def frame_manager
7
+ PryStackExplorer.frame_manager(_pry_)
8
+ end
9
+
10
+ def frame_managers
11
+ PryStackExplorer.frame_managers(_pry_)
12
+ end
7
13
 
8
- if !PryStackExplorer.frame_manager(_pry_)
9
- output.puts "Nowhere to go!"
14
+ def prior_context_exists?
15
+ frame_managers.count > 1 || frame_manager.prior_binding
16
+ end
17
+
18
+ # Return a description of the passed binding object. Accepts an
19
+ # optional `verbose` parameter.
20
+ # @param [Binding] b The binding.
21
+ # @param [Boolean] verbose Whether to generate a verbose description.
22
+ # @return [String] The description of the binding.
23
+ def frame_info(b, verbose = false)
24
+ meth = b.eval('__method__')
25
+ b_self = b.eval('self')
26
+ meth_obj = Pry::Method.from_binding(b) if meth
27
+
28
+ type = b.frame_type ? "[#{b.frame_type}]".ljust(9) : ""
29
+ desc = b.frame_description ? "#{b.frame_description}" : "#{PryStackExplorer.frame_manager(_pry_).frame_info_for(b)}"
30
+ sig = meth_obj ? "<#{signature_with_owner(meth_obj)}>" : ""
31
+
32
+ self_clipped = "#{Pry.view_clip(b_self)}"
33
+ path = "@ #{b.eval('__FILE__')}:#{b.eval('__LINE__')}"
34
+
35
+ if !verbose
36
+ "#{type} #{desc} #{sig}"
10
37
  else
11
- binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
12
- PryStackExplorer.frame_manager(_pry_).change_frame_to binding_index + inc
38
+ "#{type} #{desc} #{sig}\n in #{self_clipped} #{path}"
13
39
  end
14
40
  end
41
+ end
15
42
 
16
- command "down", "Go down to the callee's context. Accepts optional numeric parameter for how many frames to move down." do |inc_str|
17
- inc = inc_str.nil? ? 1 : inc_str.to_i
43
+ Commands = Pry::CommandSet.new do
44
+ command_class "up", "Go up to the caller's context. Accepts optional numeric parameter for how many frames to move up." do
45
+ include FrameHelpers
18
46
 
19
- if !PryStackExplorer.frame_manager(_pry_)
20
- output.puts "Nowhere to go!"
21
- else
22
- binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
23
- if binding_index - inc < 0
24
- raise Pry::CommandError, "At bottom of stack, cannot go further!"
47
+ banner <<-BANNER
48
+ Usage: up [OPTIONS]
49
+ Go up to the caller's context. Accepts optional numeric parameter for how many frames to move up.
50
+ e.g: up
51
+ e.g: up 3
52
+ BANNER
53
+
54
+ def process
55
+ inc = args.first.nil? ? 1 : args.first.to_i
56
+
57
+ if !frame_manager
58
+ raise Pry::CommandError, "Nowhere to go!"
25
59
  else
26
- PryStackExplorer.frame_manager(_pry_).change_frame_to binding_index - inc
60
+ frame_manager.change_frame_to frame_manager.binding_index + inc
61
+ end
62
+ end
63
+ end
64
+
65
+ command_class "down", "Go down to the callee's context. Accepts optional numeric parameter for how many frames to move down." do
66
+ include FrameHelpers
67
+
68
+ banner <<-BANNER
69
+ Usage: down [OPTIONS]
70
+ Go down to the callee's context. Accepts optional numeric parameter for how many frames to move down.
71
+ e.g: down
72
+ e.g: down 3
73
+ BANNER
74
+
75
+ def process
76
+ inc = args.first.nil? ? 1 : args.first.to_i
77
+
78
+ if !frame_manager
79
+ raise Pry::CommandError, "Nowhere to go!"
80
+ else
81
+ if frame_manager.binding_index - inc < 0
82
+ raise Pry::CommandError, "At bottom of stack, cannot go further!"
83
+ else
84
+ frame_manager.change_frame_to frame_manager.binding_index - inc
85
+ end
27
86
  end
28
87
  end
29
88
  end
30
89
 
31
90
  command_class "show-stack", "Show all frames" do
32
- def options(opt)
33
- opt.banner unindent <<-USAGE
34
- Usage: show-stack [OPTIONS]
35
- Show all accessible stack frames.
36
- e.g: show-stack -v
37
- USAGE
91
+ include FrameHelpers
92
+
93
+ banner <<-BANNER
94
+ Usage: show-stack [OPTIONS]
95
+ Show all accessible stack frames.
96
+ e.g: show-stack -v
97
+ BANNER
38
98
 
99
+ def options(opt)
39
100
  opt.on :v, :verbose, "Include extra information."
40
101
  end
41
102
 
42
103
  def process
43
- if !PryStackExplorer.frame_manager(_pry_)
104
+ if !frame_manager
44
105
  output.puts "No caller stack available!"
45
106
  else
46
107
  content = ""
47
108
  content << "\n#{text.bold('Showing all accessible frames in stack:')}\n--\n"
48
109
 
49
- PryStackExplorer.frame_manager(_pry_).each_with_index do |b, i|
50
- if i == PryStackExplorer.frame_manager(_pry_).binding_index
110
+ frame_manager.each_with_index do |b, i|
111
+ if i == frame_manager.binding_index
51
112
  content << "=> ##{i} #{frame_info(b, opts[:v])}\n"
52
113
  else
53
114
  content << " ##{i} #{frame_info(b, opts[:v])}\n"
@@ -57,41 +118,9 @@ module PryStackExplorer
57
118
  stagger_output content
58
119
  end
59
120
  end
60
- end
61
-
62
- command "frame", "Switch to a particular frame. Accepts numeric parameter for the target frame to switch to (use with show-stack). Negative frame numbers allowed." do |frame_num|
63
- if !PryStackExplorer.frame_manager(_pry_)
64
- output.puts "nowhere to go!"
65
- else
66
- if frame_num
67
- PryStackExplorer.frame_manager(_pry_).change_frame_to frame_num.to_i
68
- else
69
- output.puts "##{PryStackExplorer.frame_manager(_pry_).binding_index} #{frame_info(target, true)}"
70
- end
71
- end
72
- end
73
-
74
- helpers do
75
- def frame_info(b, verbose = false)
76
- meth = b.eval('__method__')
77
- b_self = b.eval('self')
78
- meth_obj = Pry::Method.from_binding(b) if meth
79
-
80
- type = b.frame_type ? "[#{b.frame_type}]".ljust(9) : ""
81
- desc = b.frame_description ? "#{b.frame_description}" : "#{PryStackExplorer.frame_manager(_pry_).frame_info_for(b)}"
82
- sig = meth_obj ? "<#{se_signature_with_owner(meth_obj)}>" : ""
83
-
84
- self_clipped = "#{Pry.view_clip(b_self)}"
85
- path = "@ #{b.eval('__FILE__')}:#{b.eval('__LINE__')}"
86
-
87
- if !verbose
88
- "#{type} #{desc} #{sig}"
89
- else
90
- "#{type} #{desc} #{sig}\n in #{self_clipped} #{path}"
91
- end
92
- end
93
121
 
94
- def se_signature_with_owner(meth_obj)
122
+ private
123
+ def signature_with_owner(meth_obj)
95
124
  if !meth_obj.undefined?
96
125
  args = meth_obj.parameters.inject([]) do |arr, (type, name)|
97
126
  name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
@@ -107,9 +136,34 @@ module PryStackExplorer
107
136
  else
108
137
  "#{meth_obj.name_with_owner}(UNKNOWN) (undefined method)"
109
138
  end
110
-
111
139
  end
112
140
  end
113
141
 
142
+ # TODO: currently using `arg_string` as a work-around for a Slop
143
+ # bug where `-2` (negative number) is interpreted as a
144
+ # non-existent option rather than a non-option
145
+ command_class "frame", "Switch to a particular frame. Accepts numeric parameter for the target frame to switch to (use with show-stack). Negative frame numbers allowed." do
146
+ include FrameHelpers
147
+
148
+ banner <<-BANNER
149
+ Usage: frame [OPTIONS]
150
+ Switch to a particular frame. Accepts numeric parameter for the target frame to switch to (use with show-stack). Negative frame numbers allowed.
151
+ e.g: frame 4
152
+ e.g: frame -2
153
+ BANNER
154
+
155
+ def process
156
+ if !frame_manager
157
+ raise Pry::CommandError, "nowhere to go!"
158
+ else
159
+
160
+ if !arg_string.empty?
161
+ frame_manager.change_frame_to arg_string.to_i
162
+ else
163
+ output.puts "##{frame_manager.binding_index} #{frame_info(target, true)}"
164
+ end
165
+ end
166
+ end
167
+ end
114
168
  end
115
169
  end
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = "0.2.9pre3"
2
+ VERSION = "0.2.9pre4"
3
3
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry-stack_explorer"
5
- s.version = "0.2.9pre3"
5
+ s.version = "0.2.9pre4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2012-01-14"
9
+ s.date = "2012-01-16"
10
10
  s.description = "Walk the stack in a Pry session"
11
11
  s.email = "jrmair@gmail.com"
12
12
  s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example.rb", "examples/example2.rb", "lib/pry-stack_explorer.rb", "lib/pry-stack_explorer/commands.rb", "lib/pry-stack_explorer/frame_manager.rb", "lib/pry-stack_explorer/version.rb", "lib/pry-stack_explorer/when_started_hook.rb", "pry-stack_explorer.gemspec", "test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb", "tester.rb"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pry-stack_explorer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 5
5
- version: 0.2.9pre3
5
+ version: 0.2.9pre4
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Mair (banisterfiend)
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-14 00:00:00 Z
13
+ date: 2012-01-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: binding_of_caller