Skip to content

Commit

Permalink
Version 0.4.2
Browse files Browse the repository at this point in the history
* 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
banister committed Jan 26, 2011
1 parent 228b95f commit 8682e26
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 12 deletions.
25 changes: 25 additions & 0 deletions 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.
7 changes: 6 additions & 1 deletion Rakefile
Expand Up @@ -25,7 +25,7 @@ def apply_spec_defaults(s)
s.homepage = "http://banisterfiend.wordpress.com" s.homepage = "http://banisterfiend.wordpress.com"
s.has_rdoc = 'yard' s.has_rdoc = 'yard'
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb", 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 end


task :test do task :test do
Expand All @@ -43,6 +43,11 @@ task :pry do
Pry.start Pry.start
end end


desc "show pry version"
task :version do
puts "Pry version: #{Pry::VERSION}"
end

namespace :ruby do namespace :ruby do
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
apply_spec_defaults(s) apply_spec_defaults(s)
Expand Down
17 changes: 10 additions & 7 deletions lib/pry/commands.rb
Expand Up @@ -76,14 +76,17 @@ class Commands < CommandBase
end end


command "show_method", "Show sourcecode for method <methname>." do |meth_name| command "show_method", "Show sourcecode for method <methname>." do |meth_name|
meth_name = target.eval("__method__").to_s if !meth_name if meth_name
puts "blah #{meth_name.to_s}" meth_name = target.eval("__method__").to_s if !meth_name
doc = target.eval("method(\"#{meth_name}\")").source doc = target.eval("method(\"#{meth_name}\")").source
output.puts doc output.puts doc
else
output.puts "Error: Not in a method."
end
end end


command "show_imethod", "Show sourcecode for instance method <methname>." do |meth_name| 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 output.puts doc
end end


Expand All @@ -103,11 +106,11 @@ class Commands < CommandBase
end end


command "ls_methods", "List all methods defined on class of receiver." do 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 end


command "ls_imethods", "List all instance methods defined on class of receiver." do 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 end


command ["exit", "quit", "back"], "End the current Pry session." do command ["exit", "quit", "back"], "End the current Pry session." do
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry class Pry
VERSION = "0.4.2pre1" VERSION = "0.4.2"
end end
36 changes: 33 additions & 3 deletions test/test.rb
Expand Up @@ -353,8 +353,38 @@ class Command3 < Pry::Commands
Object.remove_const(:Command3) Object.remove_const(:Command3)
end 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 it 'should run a command from within a command' do
class Command3 < Pry::Commands class Command01 < Pry::Commands
command "v" do command "v" do
output.puts "v command" output.puts "v command"
end end
Expand All @@ -365,10 +395,10 @@ class Command3 < Pry::Commands
end end


str_output = StringIO.new 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/ str_output.string.should =~ /v command/


Object.remove_const(:Command3) Object.remove_const(:Command01)
end end


it 'should enable an inherited method to access opts and output and target, due to instance_exec' do it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
Expand Down
23 changes: 23 additions & 0 deletions wiki/Customizing-pry.md
Expand Up @@ -200,6 +200,28 @@ being invoked:
end end
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 #### Utility methods for commands


All commands can access the special `output` and `target` methods. The All commands can access the special `output` and `target` methods. The
Expand Down Expand Up @@ -372,3 +394,4 @@ exception and precedes the output of a value by the text `"Output is: "`:
end end
end end


[Back to front page of documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)

0 comments on commit 8682e26

Please sign in to comment.