pry 0.9.8pre7-i386-mingw32 → 0.9.8pre8-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pry.rb CHANGED
@@ -148,6 +148,14 @@ class Pry
148
148
  # indicate an exceptional condition that's fatal to the current command.
149
149
  class CommandError < StandardError; end
150
150
  class NonMethodContextError < CommandError; end
151
+
152
+ # indicates obsolete API
153
+ class ObsoleteError < StandardError; end
154
+
155
+ # This is to keep from breaking under Rails 3.2 for people who are doing that
156
+ # IRB = Pry thing.
157
+ module ExtendCommandBundle
158
+ end
151
159
  end
152
160
 
153
161
  require "method_source"
@@ -163,7 +171,7 @@ if Pry::Helpers::BaseHelpers.jruby?
163
171
  begin
164
172
  require 'ffi'
165
173
  rescue LoadError
166
- $stderr.puts "Need to `gem install ffi`"
174
+ warn "Need to `gem install ffi`"
167
175
  end
168
176
  end
169
177
 
@@ -171,7 +179,7 @@ if Pry::Helpers::BaseHelpers.windows?
171
179
  begin
172
180
  require 'win32console'
173
181
  rescue LoadError
174
- $stderr.puts "Need to `gem install win32console`"
182
+ warn "Need to `gem install win32console`"
175
183
  exit 1
176
184
  end
177
185
  end
data/lib/pry/code.rb CHANGED
@@ -122,7 +122,7 @@ class Pry
122
122
  # @return [String] The inserted line.
123
123
  def push(line, line_num=nil)
124
124
  line_num = @lines.last.last + 1 unless line_num
125
- @lines.push([line, line_num])
125
+ @lines.push([line.chomp, line_num])
126
126
  line
127
127
  end
128
128
  alias << push
@@ -305,6 +305,13 @@ class Pry
305
305
  lines.map { |l| "#{l.first}\n" }.join
306
306
  end
307
307
 
308
+ # Return an unformatted String of the code.
309
+ #
310
+ # @return [String]
311
+ def raw
312
+ @lines.map(&:first).join("\n")
313
+ end
314
+
308
315
  # Return the number of lines stored.
309
316
  #
310
317
  # @return [Fixnum]
data/lib/pry/command.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Pry
2
2
 
3
3
  # The super-class of all commands, new commands should be created by calling
4
- # {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#command_class}
4
+ # {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#create_command}
5
5
  # which creates a ClassCommand. Please don't use this class directly.
6
6
  class Command
7
7
 
@@ -12,7 +12,7 @@ class Pry
12
12
  def VOID_VALUE.inspect() "void" end
13
13
 
14
14
  # Properties of the command itself (as passed as arguments to
15
- # {CommandSet#command} or {CommandSet#command_class}).
15
+ # {CommandSet#command} or {CommandSet#create_command}).
16
16
  class << self
17
17
  attr_accessor :block
18
18
  attr_accessor :name
@@ -331,7 +331,7 @@ class Pry
331
331
  # This class implements the bare-minimum functionality that a command should have,
332
332
  # namely a --help switch, and then delegates actual processing to its subclasses.
333
333
  #
334
- # Create subclasses using {Pry::CommandSet#command_class}, and override the {options(opt)} method
334
+ # Create subclasses using {Pry::CommandSet#create_command}, and override the {options(opt)} method
335
335
  # to set up an instance of Slop, and the {process} method to actually run the command. If
336
336
  # necessary, you can also override {setup} which will be called before {options}, for example to
337
337
  # require any gems your command needs to run, or to set up state.
@@ -122,7 +122,6 @@ class Pry
122
122
  commands[name].class_eval(&block)
123
123
  commands[name]
124
124
  end
125
- alias_method :command_class, :create_command
126
125
 
127
126
  # Execute a block of code before a command is invoked. The block also
128
127
  # gets access to parameters that will be passed to the command and
@@ -365,45 +364,49 @@ class Pry
365
364
  end
366
365
  end
367
366
 
368
- command "install-command", "Install a disabled command." do |name|
369
- require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
370
- command = find_command(name)
367
+ create_command "install-command", "Install a disabled command." do |name|
371
368
 
372
- if command_dependencies_met?(command.options)
373
- output.puts "Dependencies for #{command.name} are met. Nothing to do."
374
- next
375
- end
369
+ banner <<-BANNER
370
+ Usage: install-command COMMAND
376
371
 
377
- output.puts "Attempting to install `#{name}` command..."
378
- gems_to_install = Array(command.options[:requires_gem])
372
+ Installs the gems necessary to run the given COMMAND. You will generally not
373
+ need to run this unless told to by an error message.
374
+ BANNER
379
375
 
380
- gem_install_failed = false
381
- gems_to_install.each do |g|
382
- next if gem_installed?(g)
383
- output.puts "Installing `#{g}` gem..."
376
+ def process(name)
377
+ require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
378
+ command = find_command(name)
384
379
 
385
- begin
386
- Gem::DependencyInstaller.new.install(g)
387
- rescue Gem::GemNotFoundException
388
- output.puts "Required Gem: `#{g}` not found. Aborting command installation."
389
- gem_install_failed = true
390
- next
380
+ if command_dependencies_met?(command.options)
381
+ output.puts "Dependencies for #{command.name} are met. Nothing to do."
382
+ return
391
383
  end
392
- end
393
- next if gem_install_failed
394
-
395
- Gem.refresh
396
- gems_to_install.each do |g|
397
- begin
398
- require g
399
- rescue LoadError
400
- output.puts "Required Gem: `#{g}` installed but not found?!. Aborting command installation."
401
- gem_install_failed = true
384
+
385
+ output.puts "Attempting to install `#{name}` command..."
386
+ gems_to_install = Array(command.options[:requires_gem])
387
+
388
+ gems_to_install.each do |g|
389
+ next if gem_installed?(g)
390
+ output.puts "Installing `#{g}` gem..."
391
+
392
+ begin
393
+ Gem::DependencyInstaller.new.install(g)
394
+ rescue Gem::GemNotFoundException
395
+ raise CommandError, "Required Gem: `#{g}` not found. Aborting command installation."
396
+ end
397
+ end
398
+
399
+ Gem.refresh
400
+ gems_to_install.each do |g|
401
+ begin
402
+ require g
403
+ rescue LoadError
404
+ raise CommandError, "Required Gem: `#{g}` installed but not found?!. Aborting command installation."
405
+ end
402
406
  end
403
- end
404
- next if gem_install_failed
405
407
 
406
- output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
408
+ output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
409
+ end
407
410
  end
408
411
  end
409
412
  end
data/lib/pry/config.rb CHANGED
@@ -42,7 +42,19 @@ class Pry
42
42
  # @example
43
43
  # Pry.hooks :before_session => proc { puts "hello" },
44
44
  # :after_session => proc { puts "goodbye" }
45
- attr_accessor :hooks
45
+ attr_reader :hooks
46
+
47
+ # FIXME:
48
+ # This is a hack to alert people of the new API.
49
+ # @param [Pry::Hooks] v Only accept `Pry::Hooks` now!
50
+ def hooks=(v)
51
+ if v.is_a?(Hash)
52
+ warn "Hash-based hooks are now deprecated! Use a `Pry::Hooks` object instead! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
53
+ @hooks = Pry::Hooks.from_hash(v)
54
+ else
55
+ @hooks = v
56
+ end
57
+ end
46
58
 
47
59
  # Get/Set the stack of input objects that a Pry instance switches
48
60
  # to when its current input object encounters EOF.
@@ -6,7 +6,7 @@ class Pry
6
6
  Context = Pry::CommandSet.new do
7
7
  import Ls
8
8
 
9
- command_class "cd" do
9
+ create_command "cd" do
10
10
  description "Move into a new context (object or scope). Type `cd --help` for more information."
11
11
 
12
12
  banner <<-BANNER
@@ -106,7 +106,7 @@ class Pry
106
106
 
107
107
  alias_command "!!@", "exit-all"
108
108
 
109
- command_class "exit" do
109
+ create_command "exit" do
110
110
  description "Pop the previous binding (does NOT exit program). Type `exit --help` for more information. Aliases: quit"
111
111
 
112
112
  banner <<-BANNER
@@ -164,11 +164,16 @@ class Pry
164
164
  target.pry
165
165
  end
166
166
 
167
- command_class "pry-backtrace", "Show the backtrace for the Pry session." do
167
+ create_command "pry-backtrace", "Show the backtrace for the Pry session." do
168
168
  banner <<-BANNER
169
169
  Usage: pry-backtrace [OPTIONS] [--help]
170
170
 
171
- Show the backtrace for the Pry session.
171
+ Show the backtrace for the position in the code where Pry was started. This can be used to
172
+ infer the behavior of the program immediately before it entered Pry, just like the backtrace
173
+ property of an exception.
174
+
175
+ (NOTE: if you are looking for the backtrace of the most recent exception raised,
176
+ just type: `_ex_.backtrace` instead, see https://github.com/pry/pry/wiki/Special-Locals)
172
177
 
173
178
  e.g: pry-backtrace
174
179
  BANNER
@@ -3,7 +3,7 @@ class Pry
3
3
 
4
4
  Documentation = Pry::CommandSet.new do
5
5
 
6
- command_class "ri", "View ri documentation. e.g `ri Array#each`" do
6
+ create_command "ri", "View ri documentation. e.g `ri Array#each`" do
7
7
  banner <<-BANNER
8
8
  Usage: ri [spec]
9
9
  e.g. ri Array#each
@@ -16,7 +16,7 @@ class Pry
16
16
  end
17
17
  end
18
18
 
19
- command_class "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?", :shellwords => false do |*args|
19
+ create_command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?", :shellwords => false do |*args|
20
20
  banner <<-BANNER
21
21
  Usage: show-doc [OPTIONS] [METH]
22
22
  Show the comments above method METH. Tries instance methods first and then methods by default.
@@ -25,6 +25,8 @@ class Pry
25
25
 
26
26
  def options(opt)
27
27
  method_options(opt)
28
+ opt.on :l, "line-numbers", "Show line numbers."
29
+ opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)."
28
30
  opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
29
31
  end
30
32
 
@@ -39,13 +41,27 @@ class Pry
39
41
  output.puts "#{text.bold("Signature:")} #{meth.signature}"
40
42
  output.puts
41
43
 
44
+ if opts.present?(:b) || opts.present?(:l)
45
+ doc = Code.new(doc, start_line, :text).
46
+ with_line_numbers(true)
47
+ end
48
+
42
49
  render_output(doc, opts)
43
50
  end
51
+
52
+ def start_line
53
+ if opts.present?(:'base-one')
54
+ 1
55
+ else
56
+ (method_object.source_line - method_object.doc.lines.count) || 1
57
+ end
58
+ end
59
+
44
60
  end
45
61
 
46
62
  alias_command "?", "show-doc"
47
63
 
48
- command_class "stat", "View method information and set _file_ and _dir_ locals. Type `stat --help` for more info.", :shellwords => false do |*args|
64
+ create_command "stat", "View method information and set _file_ and _dir_ locals. Type `stat --help` for more info.", :shellwords => false do |*args|
49
65
  banner <<-BANNER
50
66
  Usage: stat [OPTIONS] [METH]
51
67
  Show method information for method METH and set _file_ and _dir_ locals.
@@ -72,67 +88,55 @@ class Pry
72
88
  end
73
89
  end
74
90
 
75
- command_class "gist", "Gist a method or expression history to github. Type `gist --help` for more info.", :requires_gem => "gist", :shellwords => false do
91
+ create_command "gist", "Gist a method or expression history to github. Type `gist --help` for more info.", :requires_gem => "gist", :shellwords => false do
92
+ banner <<-USAGE
93
+ Usage: gist [OPTIONS] [METH]
94
+ Gist method (doc or source) or input expression to github.
95
+ Ensure the `gist` gem is properly working before use. http://github.com/defunkt/gist for instructions.
96
+ e.g: gist -m my_method
97
+ e.g: gist -d my_method
98
+ e.g: gist -i 1..10
99
+ e.g: gist -c show-method
100
+ e.g: gist -m hello_world --lines 2..-2
101
+ USAGE
102
+
76
103
  attr_accessor :content
77
104
  attr_accessor :code_type
78
- attr_accessor :input_ranges
79
105
 
80
106
  def setup
81
107
  require 'gist'
108
+ self.content = ""
109
+ self.code_type = :ruby
82
110
  end
83
111
 
84
112
  def options(opt)
85
- opt.banner unindent <<-USAGE
86
- Usage: gist [OPTIONS] [METH]
87
- Gist method (doc or source) or input expression to github.
88
- Ensure the `gist` gem is properly working before use. http://github.com/defunkt/gist for instructions.
89
- e.g: gist -m my_method
90
- e.g: gist -d my_method
91
- e.g: gist -i 1..10
92
- e.g: gist -c show-method
93
- USAGE
94
-
95
- opt.on :d, :doc, "Gist a method's documentation.", true
96
- opt.on :m, :method, "Gist a method's source.", true
97
- opt.on :c, :command, "Gist a command's source.", true
98
- opt.on :f, :file, "Gist a file.", true
99
- opt.on :p, :public, "Create a public gist (default: false)", :default => false
100
- opt.on :l, :lines, "Only gist a subset of lines (only works with -m and -f)", :optional => true, :as => Range, :default => 1..-1
101
- opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional => true,
102
- :as => Range, :default => -5..-1 do |range|
103
- self.input_ranges ||= []
104
- input_ranges << absolute_index_range(range, _pry_.input_array.length)
105
- end
106
- end
107
-
108
- def process
109
- self.content = ""
110
-
111
- if opts.present?(:in)
112
- in_option
113
- end
114
- if opts.present?(:file)
115
- file_option
113
+ opt.on :m, :method, "Gist a method's source.", true do |meth_name|
114
+ meth = get_method_or_raise(meth_name, target, {})
115
+ self.content << meth.source
116
+ self.code_type = meth.source_type
116
117
  end
117
- if opts.present?(:doc)
118
- doc_option
118
+ opt.on :d, :doc, "Gist a method's documentation.", true do |meth_name|
119
+ meth = get_method_or_raise(meth_name, target, {})
120
+ text.no_color do
121
+ self.content << process_comment_markup(meth.doc, self.code_type)
122
+ end
123
+ self.code_type = :plain
119
124
  end
120
- if opts.present?(:method)
121
- method_option
125
+ opt.on :c, :command, "Gist a command's source.", true do |command_name|
126
+ command = find_command(command_name)
127
+ block = Pry::Method.new(find_command(command_name).block)
128
+ self.content << block.source
122
129
  end
123
- if opts.present?(:command)
124
- command_option
130
+ opt.on :f, :file, "Gist a file.", true do |file|
131
+ self.content << File.read(File.expand_path(file))
125
132
  end
126
-
127
- perform_gist
128
- end
129
-
130
- def in_option
131
- self.code_type = :ruby
132
-
133
- input_ranges.each do |range|
133
+ opt.on :p, :public, "Create a public gist (default: false)", :default => false
134
+ opt.on :l, :lines, "Only gist a subset of lines.", :optional => true, :as => Range, :default => 1..-1
135
+ opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional => true,
136
+ :as => Range, :default => -5..-1 do |range|
137
+ range = convert_to_range(range)
134
138
  input_expressions = _pry_.input_array[range] || []
135
- input_expressions.each_with_index.map do |code, index|
139
+ Array(input_expressions).each_with_index do |code, index|
136
140
  corrected_index = index + range.first
137
141
  if code && code != ""
138
142
  self.content << code
@@ -144,49 +148,8 @@ USAGE
144
148
  end
145
149
  end
146
150
 
147
- def file_option
148
- whole_file = File.read(File.expand_path(opts[:f]))
149
- if opts.present?(:lines)
150
- self.content << restrict_to_lines(whole_file, opts[:l])
151
- else
152
- self.content << whole_file
153
- end
154
- end
155
-
156
- def doc_option
157
- meth = get_method_or_raise(opts[:d], target, {})
158
- self.content << meth.doc
159
- self.code_type = meth.source_type
160
-
161
- text.no_color do
162
- self.content << process_comment_markup(self.content, self.code_type)
163
- end
164
- self.code_type = :plain
165
- end
166
-
167
- def method_option
168
- meth = get_method_or_raise(opts[:m], target, {})
169
- method_source = meth.source
170
- if opts.present?(:lines)
171
- self.content << restrict_to_lines(method_source, opts[:l])
172
- else
173
- self.content << method_source
174
- end
175
-
176
- self.code_type = meth.source_type
177
- end
178
-
179
- def command_option
180
- command = find_command(opts[:c])
181
- command_source = command.block.source
182
-
183
- if opts.present?(:lines)
184
- self.content << restrict_to_lines(command_source, opts[:l])
185
- else
186
- self.content << command_source
187
- end
188
-
189
- self.code_type = :ruby
151
+ def process
152
+ perform_gist
190
153
  end
191
154
 
192
155
  def perform_gist
@@ -200,6 +163,10 @@ USAGE
200
163
  begin
201
164
  extname = opts.present?(:file) ? ".#{gist_file_extension(opts[:f])}" : ".#{type_map[self.code_type]}"
202
165
 
166
+ if opts.present?(:lines)
167
+ self.content = restrict_to_lines(content, opts[:l])
168
+ end
169
+
203
170
  link = Gist.write([:extension => extname,
204
171
  :input => self.content],
205
172
  !opts[:p])
@@ -212,15 +179,18 @@ USAGE
212
179
  end
213
180
  end
214
181
 
215
- def restrict_to_lines(content, lines)
216
- line_range = one_index_range(lines)
217
- content.lines.to_a[line_range].join
218
- end
219
-
220
182
  def gist_file_extension(file_name)
221
183
  file_name.split(".").last
222
184
  end
223
185
 
186
+ def convert_to_range(n)
187
+ if !n.is_a?(Range)
188
+ (n..n)
189
+ else
190
+ n
191
+ end
192
+ end
193
+
224
194
  def comment_expression_result_for_gist(result)
225
195
  content = ""
226
196
  result.lines.each_with_index do |line, index|