pry 0.6.7pre4-i386-mingw32 → 0.6.8-i386-mingw32
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.
- data/CHANGELOG +88 -75
- data/LICENSE +25 -25
- data/README.markdown +321 -309
- data/Rakefile +103 -103
- data/bin/pry +83 -82
- data/examples/example_basic.rb +17 -17
- data/examples/example_command_override.rb +35 -35
- data/examples/example_commands.rb +39 -39
- data/examples/example_hooks.rb +12 -12
- data/examples/example_image_edit.rb +71 -71
- data/examples/example_input.rb +10 -10
- data/examples/example_input2.rb +32 -32
- data/examples/example_output.rb +14 -14
- data/examples/example_print.rb +9 -9
- data/examples/example_prompt.rb +12 -12
- data/lib/pry.rb +32 -32
- data/lib/pry/command_base.rb +150 -150
- data/lib/pry/commands.rb +616 -577
- data/lib/pry/completion.rb +202 -202
- data/lib/pry/core_extensions.rb +55 -55
- data/lib/pry/hooks.rb +19 -8
- data/lib/pry/print.rb +19 -19
- data/lib/pry/prompts.rb +26 -26
- data/lib/pry/pry_class.rb +219 -186
- data/lib/pry/pry_instance.rb +316 -316
- data/lib/pry/version.rb +3 -3
- data/test/test.rb +725 -681
- data/test/test_helper.rb +46 -38
- data/test/testrc +2 -0
- metadata +102 -66
data/lib/pry/hooks.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
-
class Pry
|
2
|
-
|
3
|
-
# The default hooks - display messages when beginning and ending Pry sessions.
|
4
|
-
DEFAULT_HOOKS = {
|
5
|
-
|
6
|
-
:
|
7
|
-
|
8
|
-
|
1
|
+
class Pry
|
2
|
+
|
3
|
+
# The default hooks - display messages when beginning and ending Pry sessions.
|
4
|
+
DEFAULT_HOOKS = {
|
5
|
+
|
6
|
+
:before_session => proc do |out, target|
|
7
|
+
out.puts "Beginning Pry session for #{Pry.view_clip(target.eval('self'))}"
|
8
|
+
|
9
|
+
# ensure we're actually in a method
|
10
|
+
meth_name = target.eval('__method__')
|
11
|
+
file = target.eval('__FILE__')
|
12
|
+
if ![nil, :__binding__, :__binding_impl__].include?(meth_name) && file !~ /(\(.*\))|<.*>/
|
13
|
+
Pry.run_command "whereami", :output => out, :show_output => true, :context => target, :commands => Pry::Commands
|
14
|
+
end
|
15
|
+
end,
|
16
|
+
|
17
|
+
:after_session => proc { |out, target| out.puts "Ending Pry session for #{Pry.view_clip(target.eval('self'))}" }
|
18
|
+
}
|
19
|
+
end
|
data/lib/pry/print.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
class Pry
|
2
|
-
|
3
|
-
# The default print object - only show first line of backtrace and
|
4
|
-
# prepend output with `=>`
|
5
|
-
DEFAULT_PRINT = proc do |output, value|
|
6
|
-
case value
|
7
|
-
when Exception
|
8
|
-
output.puts "#{value.class}: #{value.message}"
|
9
|
-
output.puts "from #{value.backtrace.first}"
|
10
|
-
else
|
11
|
-
if Pry.color
|
12
|
-
output.puts "=> #{CodeRay.scan(Pry.view(value), :ruby).term}"
|
13
|
-
else
|
14
|
-
output.puts "=> #{Pry.view(value)}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
1
|
+
class Pry
|
2
|
+
|
3
|
+
# The default print object - only show first line of backtrace and
|
4
|
+
# prepend output with `=>`
|
5
|
+
DEFAULT_PRINT = proc do |output, value|
|
6
|
+
case value
|
7
|
+
when Exception
|
8
|
+
output.puts "#{value.class}: #{value.message}"
|
9
|
+
output.puts "from #{value.backtrace.first}"
|
10
|
+
else
|
11
|
+
if Pry.color
|
12
|
+
output.puts "=> #{CodeRay.scan(Pry.view(value), :ruby).term}"
|
13
|
+
else
|
14
|
+
output.puts "=> #{Pry.view(value)}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/pry/prompts.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
class Pry
|
2
|
-
|
3
|
-
|
4
|
-
# The default prompt; includes the target and nesting level
|
5
|
-
DEFAULT_PROMPT = [
|
6
|
-
proc do |target_self, nest_level|
|
7
|
-
|
8
|
-
if nest_level == 0
|
9
|
-
"pry(#{Pry.view_clip(target_self)})> "
|
10
|
-
else
|
11
|
-
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}> "
|
12
|
-
end
|
13
|
-
end,
|
14
|
-
|
15
|
-
proc do |target_self, nest_level|
|
16
|
-
if nest_level == 0
|
17
|
-
"pry(#{Pry.view_clip(target_self)})* "
|
18
|
-
else
|
19
|
-
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* "
|
20
|
-
end
|
21
|
-
end
|
22
|
-
]
|
23
|
-
|
24
|
-
# A simple prompt - doesn't display target or nesting level
|
25
|
-
SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
|
26
|
-
end
|
1
|
+
class Pry
|
2
|
+
|
3
|
+
|
4
|
+
# The default prompt; includes the target and nesting level
|
5
|
+
DEFAULT_PROMPT = [
|
6
|
+
proc do |target_self, nest_level|
|
7
|
+
|
8
|
+
if nest_level == 0
|
9
|
+
"pry(#{Pry.view_clip(target_self)})> "
|
10
|
+
else
|
11
|
+
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}> "
|
12
|
+
end
|
13
|
+
end,
|
14
|
+
|
15
|
+
proc do |target_self, nest_level|
|
16
|
+
if nest_level == 0
|
17
|
+
"pry(#{Pry.view_clip(target_self)})* "
|
18
|
+
else
|
19
|
+
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* "
|
20
|
+
end
|
21
|
+
end
|
22
|
+
]
|
23
|
+
|
24
|
+
# A simple prompt - doesn't display target or nesting level
|
25
|
+
SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
|
26
|
+
end
|
data/lib/pry/pry_class.rb
CHANGED
@@ -1,186 +1,219 @@
|
|
1
|
-
# @author John Mair (banisterfiend)
|
2
|
-
class Pry
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
def self.
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
#
|
92
|
-
# @param
|
93
|
-
# @
|
94
|
-
# @
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
#
|
106
|
-
#
|
107
|
-
# @param
|
108
|
-
#
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
#
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
1
|
+
# @author John Mair (banisterfiend)
|
2
|
+
class Pry
|
3
|
+
|
4
|
+
# The RC Files to load.
|
5
|
+
RC_FILES = ["~/.pryrc"]
|
6
|
+
|
7
|
+
# class accessors
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Get nesting data.
|
11
|
+
# This method should not need to be accessed directly.
|
12
|
+
# @return [Array] The unparsed nesting information.
|
13
|
+
attr_reader :nesting
|
14
|
+
|
15
|
+
# Get last value evaluated by Pry.
|
16
|
+
# This method should not need to be accessed directly.
|
17
|
+
# @return [Object] The last result.
|
18
|
+
attr_accessor :last_result
|
19
|
+
|
20
|
+
# Get the active Pry instance that manages the active Pry session.
|
21
|
+
# This method should not need to be accessed directly.
|
22
|
+
# @return [Pry] The active Pry instance.
|
23
|
+
attr_accessor :active_instance
|
24
|
+
|
25
|
+
# Get/Set the object to use for input by default by all Pry instances.
|
26
|
+
# @return [#readline] The object to use for input by default by all
|
27
|
+
# Pry instances.
|
28
|
+
attr_accessor :input
|
29
|
+
|
30
|
+
# Get/Set the object to use for output by default by all Pry instances.
|
31
|
+
# @return [#puts] The object to use for output by default by all
|
32
|
+
# Pry instances.
|
33
|
+
attr_accessor :output
|
34
|
+
|
35
|
+
# Get/Set the object to use for commands by default by all Pry instances.
|
36
|
+
# @return [Pry::CommandBase] The object to use for commands by default by all
|
37
|
+
# Pry instances.
|
38
|
+
attr_accessor :commands
|
39
|
+
|
40
|
+
# Get/Set the Proc to use for printing by default by all Pry
|
41
|
+
# instances.
|
42
|
+
# This is the 'print' component of the REPL.
|
43
|
+
# @return [Proc] The Proc to use for printing by default by all
|
44
|
+
# Pry instances.
|
45
|
+
attr_accessor :print
|
46
|
+
|
47
|
+
# Get/Set the Hash that defines Pry hooks used by default by all Pry
|
48
|
+
# instances.
|
49
|
+
# @return [Hash] The hooks used by default by all Pry instances.
|
50
|
+
# @example
|
51
|
+
# Pry.hooks :before_session => proc { puts "hello" },
|
52
|
+
# :after_session => proc { puts "goodbye" }
|
53
|
+
attr_accessor :hooks
|
54
|
+
|
55
|
+
# Get the array of Procs to be used for the prompts by default by
|
56
|
+
# all Pry instances.
|
57
|
+
# @return [Array<Proc>] The array of Procs to be used for the
|
58
|
+
# prompts by default by all Pry instances.
|
59
|
+
attr_accessor :prompt
|
60
|
+
|
61
|
+
# Value returned by last executed Pry command.
|
62
|
+
# @return [Object] The command value
|
63
|
+
attr_accessor :cmd_ret_value
|
64
|
+
|
65
|
+
# Determines whether colored output is enabled.
|
66
|
+
# @return [Boolean]
|
67
|
+
attr_accessor :color
|
68
|
+
|
69
|
+
# Determines whether the rc file (~/.pryrc) should be loaded.
|
70
|
+
# @return [Boolean]
|
71
|
+
attr_accessor :should_load_rc
|
72
|
+
|
73
|
+
# Set to true if Pry is invoked from command line using `pry` executable
|
74
|
+
# @return [Boolean]
|
75
|
+
attr_accessor :cli
|
76
|
+
end
|
77
|
+
|
78
|
+
# Load the rc files given in the `Pry::RC_FILES` array.
|
79
|
+
# Defaults to loading just `~/.pryrc`. This method can also
|
80
|
+
# be used to reload the files if they have changed.
|
81
|
+
def self.load_rc
|
82
|
+
RC_FILES.each do |file_name|
|
83
|
+
file_name = File.expand_path(file_name)
|
84
|
+
load(file_name) if File.exists?(file_name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Start a Pry REPL.
|
89
|
+
# This method also loads the files specified in `Pry::RC_FILES` the
|
90
|
+
# first time it is invoked.
|
91
|
+
# @param [Object, Binding] target The receiver of the Pry session
|
92
|
+
# @param [Hash] options
|
93
|
+
# @option options (see Pry#initialize)
|
94
|
+
# @example
|
95
|
+
# Pry.start(Object.new, :input => MyInput.new)
|
96
|
+
def self.start(target=TOPLEVEL_BINDING, options={})
|
97
|
+
if should_load_rc && !@rc_loaded
|
98
|
+
load_rc
|
99
|
+
@rc_loaded = true
|
100
|
+
end
|
101
|
+
|
102
|
+
new(options).repl(target)
|
103
|
+
end
|
104
|
+
|
105
|
+
# A custom version of `Kernel#inspect`.
|
106
|
+
# This method should not need to be accessed directly.
|
107
|
+
# @param obj The object to view.
|
108
|
+
# @return [String] The string representation of `obj`.
|
109
|
+
def self.view(obj)
|
110
|
+
case obj
|
111
|
+
when String, Hash, Array, Symbol, nil
|
112
|
+
obj.inspect
|
113
|
+
else
|
114
|
+
obj.to_s
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# A version of `Pry.view` that clips the output to `max_size` chars.
|
119
|
+
# In case of > `max_size` chars the `#<Object...> notation is used.
|
120
|
+
# @param obj The object to view.
|
121
|
+
# @param max_size The maximum number of chars before clipping occurs.
|
122
|
+
# @return [String] The string representation of `obj`.
|
123
|
+
def self.view_clip(obj, max_size=60)
|
124
|
+
if Pry.view(obj).size < max_size
|
125
|
+
Pry.view(obj)
|
126
|
+
else
|
127
|
+
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Run a Pry command from outside a session. The commands available are
|
132
|
+
# those referenced by `Pry.commands` (the default command set).
|
133
|
+
# Command output is suppresed by default, this is because the return
|
134
|
+
# value (if there is one) is likely to be more useful.
|
135
|
+
# @param [String] arg_string The Pry command (including arguments,
|
136
|
+
# if any).
|
137
|
+
# @param [Hash] options Optional named parameters.
|
138
|
+
# @return [Object] The return value of the Pry command.
|
139
|
+
# @option options [Object, Binding] :context The object context to run the
|
140
|
+
# command under. Defaults to `TOPLEVEL_BINDING` (main).
|
141
|
+
# @option options [Boolean] :show_output Whether to show command
|
142
|
+
# output. Defaults to false.
|
143
|
+
# @example Run at top-level with no output.
|
144
|
+
# Pry.run_command "ls"
|
145
|
+
# @example Run under Pry class, returning only public methods.
|
146
|
+
# Pry.run_command "ls -m", :context => Pry
|
147
|
+
# @example Display command output.
|
148
|
+
# Pry.run_command "ls -av", :show_output => true
|
149
|
+
def self.run_command(arg_string, options={})
|
150
|
+
name, arg_string = arg_string.split(/\s+/, 2)
|
151
|
+
arg_string = "" if !arg_string
|
152
|
+
|
153
|
+
options = {
|
154
|
+
:context => TOPLEVEL_BINDING,
|
155
|
+
:show_output => false,
|
156
|
+
:output => Pry.output,
|
157
|
+
:commands => Pry.commands
|
158
|
+
}.merge!(options)
|
159
|
+
|
160
|
+
null_output = Object.new.tap { |v| v.instance_eval { def puts(*) end } }
|
161
|
+
|
162
|
+
commands = options[:commands].clone
|
163
|
+
commands.output = options[:show_output] ? options[:output] : null_output
|
164
|
+
commands.target = Pry.binding_for(options[:context])
|
165
|
+
|
166
|
+
cmd = commands.commands[name]
|
167
|
+
if cmd
|
168
|
+
action = cmd[:action]
|
169
|
+
commands.instance_exec(*Shellwords.shellwords(arg_string), &action)
|
170
|
+
else
|
171
|
+
raise "No such Pry command: #{name}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Set all the configurable options back to their default values
|
176
|
+
def self.reset_defaults
|
177
|
+
@input = Readline
|
178
|
+
@output = $stdout
|
179
|
+
@commands = Pry::Commands
|
180
|
+
@prompt = DEFAULT_PROMPT
|
181
|
+
@print = DEFAULT_PRINT
|
182
|
+
@hooks = DEFAULT_HOOKS
|
183
|
+
@color = true
|
184
|
+
@should_load_rc = true
|
185
|
+
@rc_loaded = false
|
186
|
+
@cli = false
|
187
|
+
end
|
188
|
+
|
189
|
+
self.reset_defaults
|
190
|
+
|
191
|
+
@nesting = []
|
192
|
+
def @nesting.level
|
193
|
+
last.is_a?(Array) ? last.first : nil
|
194
|
+
end
|
195
|
+
|
196
|
+
# Return all active Pry sessions.
|
197
|
+
# @return [Array<Pry>] Active Pry sessions.
|
198
|
+
def self.sessions
|
199
|
+
# last element in nesting array is the pry instance
|
200
|
+
nesting.map(&:last)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Return a `Binding` object for `target` or return `target` if it is
|
204
|
+
# already a `Binding`.
|
205
|
+
# In the case where `target` is top-level then return `TOPLEVEL_BINDING`
|
206
|
+
# @param [Object] target The object to get a `Binding` object for.
|
207
|
+
# @return [Binding] The `Binding` object.
|
208
|
+
def self.binding_for(target)
|
209
|
+
if target.is_a?(Binding)
|
210
|
+
target
|
211
|
+
else
|
212
|
+
if target == TOPLEVEL_BINDING.eval('self')
|
213
|
+
TOPLEVEL_BINDING
|
214
|
+
else
|
215
|
+
target.__binding__
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|