Version 0.4.2
* Added alias_command and desc commands to Pry::CommandBase * Added pry and version tasks to Rakefile to start a pry session and show current version * Added tests for alias_command and desc commands * made it so ls_methods and ls_imethods return sort arrays * made it so show_method without a paramater displays current method, if exists, who displays error if not
This commit is contained in:
parent
228b95f516
commit
8682e269eb
|
@ -0,0 +1,25 @@
|
|||
License
|
||||
-------
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011 John Mair (banisterfiend)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
7
Rakefile
7
Rakefile
|
@ -25,7 +25,7 @@ def apply_spec_defaults(s)
|
|||
s.homepage = "http://banisterfiend.wordpress.com"
|
||||
s.has_rdoc = 'yard'
|
||||
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
|
||||
"test/*.rb", "CHANGELOG", "README.markdown", "Rakefile", ".gemtest"]
|
||||
"test/*.rb", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", ".gemtest"]
|
||||
end
|
||||
|
||||
task :test do
|
||||
|
@ -43,6 +43,11 @@ task :pry do
|
|||
Pry.start
|
||||
end
|
||||
|
||||
desc "show pry version"
|
||||
task :version do
|
||||
puts "Pry version: #{Pry::VERSION}"
|
||||
end
|
||||
|
||||
namespace :ruby do
|
||||
spec = Gem::Specification.new do |s|
|
||||
apply_spec_defaults(s)
|
||||
|
|
|
@ -76,14 +76,17 @@ class Pry
|
|||
end
|
||||
|
||||
command "show_method", "Show sourcecode for method <methname>." do |meth_name|
|
||||
meth_name = target.eval("__method__").to_s if !meth_name
|
||||
puts "blah #{meth_name.to_s}"
|
||||
doc = target.eval("method(\"#{meth_name}\")").source
|
||||
output.puts doc
|
||||
if meth_name
|
||||
meth_name = target.eval("__method__").to_s if !meth_name
|
||||
doc = target.eval("method(\"#{meth_name}\")").source
|
||||
output.puts doc
|
||||
else
|
||||
output.puts "Error: Not in a method."
|
||||
end
|
||||
end
|
||||
|
||||
command "show_imethod", "Show sourcecode for instance method <methname>." do |meth_name|
|
||||
doc = target.eval("instance_method(#{meth_name})").source
|
||||
doc = target.eval("instance_method(\"#{meth_name}\")").source
|
||||
output.puts doc
|
||||
end
|
||||
|
||||
|
@ -103,11 +106,11 @@ class Pry
|
|||
end
|
||||
|
||||
command "ls_methods", "List all methods defined on class of receiver." do
|
||||
output.puts "#{Pry.view(target.eval('public_methods(false) + private_methods(false) + protected_methods(false)'))}"
|
||||
output.puts "#{Pry.view(target.eval('(public_methods(false) + private_methods(false) + protected_methods(false)).sort'))}"
|
||||
end
|
||||
|
||||
command "ls_imethods", "List all instance methods defined on class of receiver." do
|
||||
output.puts "#{Pry.view(target.eval('public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)'))}"
|
||||
output.puts "#{Pry.view(target.eval('(public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)).sort'))}"
|
||||
end
|
||||
|
||||
command ["exit", "quit", "back"], "End the current Pry session." do
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
class Pry
|
||||
VERSION = "0.4.2pre1"
|
||||
VERSION = "0.4.2"
|
||||
end
|
||||
|
|
36
test/test.rb
36
test/test.rb
|
@ -353,8 +353,38 @@ describe Pry do
|
|||
Object.remove_const(:Command3)
|
||||
end
|
||||
|
||||
it 'should alias a command with another command' do
|
||||
class Command6 < Pry::CommandBase
|
||||
alias_command "help2", "help"
|
||||
end
|
||||
|
||||
Command6.commands["help2"].should == Command6.commands["help"]
|
||||
# str_output = StringIO.new
|
||||
# Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command3).rep
|
||||
# str_output.string.should =~ /v command/
|
||||
|
||||
Object.remove_const(:Command6)
|
||||
end
|
||||
|
||||
it 'should change description of a command using desc' do
|
||||
|
||||
class Command7 < Pry::Commands
|
||||
end
|
||||
|
||||
orig = Command7.commands["help"][:description]
|
||||
|
||||
class Command7
|
||||
desc "help", "blah"
|
||||
end
|
||||
|
||||
Command7.commands["help"][:description].should.not == orig
|
||||
Command7.commands["help"][:description].should == "blah"
|
||||
|
||||
Object.remove_const(:Command7)
|
||||
end
|
||||
|
||||
it 'should run a command from within a command' do
|
||||
class Command3 < Pry::Commands
|
||||
class Command01 < Pry::Commands
|
||||
command "v" do
|
||||
output.puts "v command"
|
||||
end
|
||||
|
@ -365,10 +395,10 @@ describe Pry do
|
|||
end
|
||||
|
||||
str_output = StringIO.new
|
||||
Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command3).rep
|
||||
Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command01).rep
|
||||
str_output.string.should =~ /v command/
|
||||
|
||||
Object.remove_const(:Command3)
|
||||
Object.remove_const(:Command01)
|
||||
end
|
||||
|
||||
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
|
||||
|
|
|
@ -200,6 +200,28 @@ being invoked:
|
|||
end
|
||||
end
|
||||
|
||||
##### `alias_command` method
|
||||
|
||||
The `alias_command` method creates an alias of a command. The first
|
||||
parameter is the name of the new command, the second parameter is the
|
||||
name of the command to be aliased; an optional third parameter is the
|
||||
description to use for the alias. If no description is provided then
|
||||
the description of the original command is used.
|
||||
|
||||
class MyCommands < Pry::Commands
|
||||
alias_command "help2", "help", "An alias of help"
|
||||
end
|
||||
|
||||
##### `desc` method
|
||||
|
||||
The `desc` method is used to give a command a new description. The
|
||||
first parameter is the name of the command, the second parameter is
|
||||
the description.
|
||||
|
||||
class MyCommands < Pry::Commands
|
||||
desc "ls", "a new description"
|
||||
end
|
||||
|
||||
#### Utility methods for commands
|
||||
|
||||
All commands can access the special `output` and `target` methods. The
|
||||
|
@ -372,3 +394,4 @@ exception and precedes the output of a value by the text `"Output is: "`:
|
|||
end
|
||||
end
|
||||
|
||||
[Back to front page of documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
|
||||
|
|
Loading…
Reference in New Issue