Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 8682e269ebc3f5378e8c88a35150f050b2a00eac 1 parent 228b95f
@banister banister authored
View
25 LICENSE
@@ -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.
View
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)
View
17 lib/pry/commands.rb
@@ -76,14 +76,17 @@ class Commands < CommandBase
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 Commands < CommandBase
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
View
2  lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.4.2pre1"
+ VERSION = "0.4.2"
end
View
36 test/test.rb
@@ -353,8 +353,38 @@ class Command3 < Pry::Commands
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 @@ class Command3 < Pry::Commands
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
View
23 wiki/Customizing-pry.md
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.