pry 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 27/1/2010 version 0.4.4
2
+ * oops, added examples/ directory
3
+ 26/1/2010 version 0.4.3
4
+ * added alias_command and desc methods to Pry::CommandBase
5
+ * changed behaviour of ls_methods and ls_imethods to return sorted lists
6
+ of methods
1
7
  23/1/2010 version 0.4.1
2
8
  * made it so a 'def meth;end' in an object Pry session defines singleton
3
9
  methods, not methods on the class (except in the case of
@@ -6,7 +12,7 @@
6
12
  * storing wiki in a nested git repo, as github wiki pages have their own
7
13
  repo
8
14
  * added more tests for new method definition behaviour
9
- 21/1/2010 version 0.4.0
15
+ x21/1/2010 version 0.4.0
10
16
  * added command API
11
17
  * added many new commands, i.e ls_methods and friends
12
18
  * modified other commands
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ def apply_spec_defaults(s)
24
24
  s.add_development_dependency("bacon",">=1.1.0")
25
25
  s.homepage = "http://banisterfiend.wordpress.com"
26
26
  s.has_rdoc = 'yard'
27
- s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
27
+ s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb", "examples/**/*.rb",
28
28
  "test/*.rb", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", ".gemtest"]
29
29
  end
30
30
 
@@ -0,0 +1,35 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Inherit standard command set, but tweak them by importing some and
7
+ # overriding others.
8
+ # Illustrates use of `command`, `run`, and `import_from` commands.
9
+ class MyCommands < Pry::CommandBase
10
+
11
+ # Override ls command
12
+ command "ls", "An unhelpful ls" do
13
+ output.puts "No, i refuse to display any useful information."
14
+ end
15
+
16
+ # bring in just the status command from Pry::Commands
17
+ import_from Pry::Commands, "status"
18
+
19
+ # analagy to Ruby's native alias_method idiom for decorating a method
20
+ alias_command "old_status", "status", ""
21
+
22
+ # Invoke one command from within another using `run`
23
+ command "status", "Modified status." do |x|
24
+ output.puts "About to show status, are you ready?"
25
+ run "old_status", x
26
+ output.puts "Finished showing status."
27
+ end
28
+
29
+ # bring in a few other commands
30
+ import_from Pry::Commands, "quit", "show_method"
31
+ end
32
+
33
+ # Start a Pry session using the commands defined in MyCommands
34
+ # Type 'help' in Pry to get a list of the commands and their descriptions
35
+ Pry.start(TOPLEVEL_BINDING, :commands => MyCommands)
@@ -0,0 +1,39 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ class MathCommands < Pry::CommandBase
7
+ command "greet", "Greet a person, e.g: greet john" do |name|
8
+ output.puts "Good afternoon #{name.capitalize}! Do you like Math?"
9
+ end
10
+
11
+ command "add", "Add a list of numbers together, e.g: add 1 2 3 4" do |*args|
12
+ output.puts "Total: #{args.map(&:to_f).inject(&:+)}"
13
+ end
14
+
15
+ command "multiply", "Multiply a list of numbers together, e.g: multiply 1 2 3 4" do |*args|
16
+ output.puts "Total: #{args.map(&:to_f).inject(&:*)}"
17
+ end
18
+
19
+ # Explicitly giving a description of "" to prevent command being
20
+ # displayed in 'help'
21
+ command "exit", "" do
22
+ throw :breakout, 0
23
+ end
24
+
25
+ # Bring in the "!" method from Pry::Commands
26
+ import_from Pry::Commands, "!"
27
+ end
28
+
29
+ # Since we provide math commands, let's have mathematical
30
+ # before_session and after_session hooks, and a mathematical prompt
31
+ math_prompt = [proc { "math> " }, proc { "math* " }]
32
+ math_hooks = {
33
+ :before_session => proc { |output, *| output.puts "Welcome! Let's do some math! Type 'help' for a list of commands." },
34
+ :after_session => proc { |output, *| output.puts "Goodbye!" }
35
+ }
36
+
37
+ # Start a Pry session using the commands defined in MyCommands
38
+ # Type 'help' in Pry to get a list of the commands and their descriptions
39
+ Pry.start(TOPLEVEL_BINDING, :commands => MathCommands, :prompt => math_prompt, :hooks => math_hooks)
@@ -0,0 +1,12 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ my_hooks = {
7
+ :before_session => proc { |out, obj| out.puts "Opening #{obj}." },
8
+ :after_session => proc { |out, obj| out.puts "Closing #{obj}." }
9
+ }
10
+
11
+ # Start a Pry session using the hooks hash defined in my_hooks
12
+ Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks)
@@ -0,0 +1,70 @@
1
+ # Note: this requires you to have Gosu and TexPlay installed.
2
+ # `gem install gosu`
3
+ # `gem install texplay`
4
+ #
5
+ # Extra instructions for installing Gosu on Linux can be found here:
6
+ # http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
7
+ #
8
+ # Instructions for using TexPlay can be found here:
9
+ # http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
10
+ #
11
+ # Have fun! :)
12
+
13
+ direc = File.dirname(__FILE__)
14
+
15
+ require 'rubygems'
16
+ require "texplay"
17
+ require "#{direc}/../lib/pry"
18
+
19
+ WIDTH = 640
20
+ HEIGHT = 480
21
+
22
+ IMAGE_PROMPT = [ proc { "(image edit)> " }, proc { "(image edit)* " } ]
23
+
24
+ class ImageCommands < Pry::CommandBase
25
+ command "drawing_methods", "Show a list of TexPlay methods" do
26
+ output.puts "#{Pry.view(TexPlay.public_instance_methods)}"
27
+ end
28
+
29
+ command "exit", "Exit the program." do
30
+ output.puts "Thanks for dropping by!"
31
+ exit
32
+ end
33
+
34
+ import_from Pry::Commands, "ls", "ls_methods", "!"
35
+ end
36
+
37
+ class WinClass < Gosu::Window
38
+
39
+ def initialize
40
+ super(WIDTH, HEIGHT, false)
41
+ @img = TexPlay.create_image(self, 200, 200).clear :color => :black
42
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
43
+
44
+ @binding = @img.__binding__
45
+
46
+ @pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
47
+ end
48
+
49
+ def draw
50
+ @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
51
+ end
52
+
53
+ def update
54
+ exit if button_down?(Gosu::KbEscape)
55
+
56
+ # We do not want a REPL session as the loop prevents the image
57
+ # being updated; instead we do a REP session, and let the image
58
+ # update each time the user presses enter. We maintain the same
59
+ # binding object to keep locals between calls to `Pry#rep()`
60
+ @pry_instance.rep(@binding)
61
+ end
62
+ end
63
+
64
+ puts "Welcome to ImageEdit; type `help` for a list of commands and `drawing_methods` for a list of drawing methods available."
65
+ puts "--"
66
+ puts "Example: Try typing 'circle width/2, height/2, 95, :color => :blue, :fill => true'"
67
+ puts "If you want to save your image, type: save(\"img.png\")"
68
+
69
+ WinClass.new.show
70
+
@@ -0,0 +1,10 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Create a StringIO that contains the input data
7
+ str_input = StringIO.new("puts 'hello world!'\nputs \"I am in \#{self}\"\nexit")
8
+
9
+ # Start a Pry session on the Fixnum 5 using the input data in str_input
10
+ Pry.start(5, :input => str_input)
@@ -0,0 +1,32 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Create a StringIO that contains the input data for all the Pry objects
7
+ cmds = <<-CMDS
8
+ cd 1
9
+ status
10
+ puts 'hello from 1!!'
11
+ cd 2
12
+ nesting
13
+ puts 'hello from 2!!'
14
+ _pry_.parent.input = Readline
15
+ back
16
+ exit_all
17
+ CMDS
18
+
19
+ # create our StringIO object
20
+ str_input = StringIO.new(cmds)
21
+
22
+ # set global input to str_input, this means that all pry sessions
23
+ # adopt this object as their input object.
24
+ Pry.input = str_input
25
+
26
+ # Start the session reading from str_input.
27
+ # Note that because `Pry.input` is set to `str_input` all nested pry
28
+ # sessions will read from `str_input` too. All pry sessions are there
29
+ # for non-interactive, except for `pry(1)` which starts off
30
+ # non-interactive but is set to be interactive by pry(2) (using
31
+ # _pry_.parent.input = Readline)
32
+ 0.pry
@@ -0,0 +1,14 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Create a StringIO to contain the output data
7
+ str_output = StringIO.new
8
+
9
+ # Start a Pry session on the Fixnum 5 using str_output to store the
10
+ # output (not writing to $stdout)
11
+ Pry.start(5, :output => str_output)
12
+
13
+ # Display all the output accumulated during the session
14
+ puts str_output.string
@@ -0,0 +1,9 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ my_print = proc { |out, value| out.puts "Output is: #{value.inspect}" }
7
+
8
+ # Start a Pry session using the print object defined in my_print
9
+ Pry.start(TOPLEVEL_BINDING, :print => my_print)
@@ -0,0 +1,12 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Remember, first prompt in array is the main prompt, second is the wait
7
+ # prompt (used for multiline input when more input is required)
8
+ my_prompt = [ proc { |obj, *| "inside #{obj}> " },
9
+ proc { |obj, *| "inside #{obj}* "} ]
10
+
11
+ # Start a Pry session using the prompt defined in my_prompt
12
+ Pry.start(TOPLEVEL_BINDING, :prompt => my_prompt)
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 3
9
- version: 0.4.3
8
+ - 4
9
+ version: 0.4.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mair (banisterfiend)
@@ -82,6 +82,15 @@ files:
82
82
  - lib/pry/pry_instance.rb
83
83
  - lib/pry/version.rb
84
84
  - lib/pry.rb
85
+ - examples/example_commands.rb
86
+ - examples/example_command_override.rb
87
+ - examples/example_hooks.rb
88
+ - examples/example_image_edit.rb
89
+ - examples/example_input.rb
90
+ - examples/example_input2.rb
91
+ - examples/example_output.rb
92
+ - examples/example_print.rb
93
+ - examples/example_prompt.rb
85
94
  - test/test.rb
86
95
  - test/test_helper.rb
87
96
  - CHANGELOG