pry 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +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)
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)
@@ -1,32 +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
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
@@ -1,14 +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
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
@@ -1,9 +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)
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)
@@ -1,12 +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
+ 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,150 +1,150 @@
1
- class Pry
2
-
3
- # Basic command functionality. All user-defined commands must
4
- # inherit from this class. It provides the `command` method.
5
- class CommandBase
6
- class << self
7
- attr_accessor :commands
8
- attr_accessor :opts, :output, :target
9
-
10
- # private because we want to force function style invocation. We require
11
- # that the location where the block is defined has the `opts`
12
- # method in scope.
13
- private
14
-
15
- # Defines a new Pry command.
16
- # @param [String, Array] names The name of the command (or array of
17
- # command name aliases).
18
- # @param [String] description A description of the command.
19
- # @param [Hash] options The optional configuration parameters.
20
- # @option options [Boolean] :keep_retval Whether or not to use return value
21
- # of the block for return of `command` or just to return `nil`
22
- # (the default).
23
- # @yield The action to perform. The parameters in the block
24
- # determines the parameters the command will receive. All
25
- # parameters passed into the block will be strings. Successive
26
- # command parameters are separated by whitespace at the Pry prompt.
27
- # @example
28
- # class MyCommands < Pry::CommandBase
29
- # command "greet", "Greet somebody" do |name|
30
- # puts "Good afternoon #{name.capitalize}!"
31
- # end
32
- # end
33
- #
34
- # # From pry:
35
- # # pry(main)> _pry_.commands = MyCommands
36
- # # pry(main)> greet john
37
- # # Good afternoon John!
38
- # # pry(main)> help greet
39
- # # Greet somebody
40
- def command(names, description="No description.", options={}, &block)
41
- options = {
42
- :keep_retval => false
43
- }.merge!(options)
44
-
45
- @commands ||= {}
46
-
47
- Array(names).each do |name|
48
- commands[name] = {
49
- :description => description,
50
- :action => block,
51
- :keep_retval => options[:keep_retval]
52
- }
53
- end
54
- end
55
-
56
- # Delete a command or an array of commands.
57
- # Useful when inheriting from another command set and pruning
58
- # those commands down to the ones you want.
59
- # @param [Array<String>] names The command name or array
60
- # of command names you want to delete
61
- # @example Deleteing inherited commands
62
- # class MyCommands < Pry::Commands
63
- # delete "show_method", "show_imethod", "show_doc", "show_idoc"
64
- # end
65
- # Pry.commands = MyCommands
66
- def delete(*names)
67
- names.each { |name| commands.delete(name) }
68
- end
69
-
70
- # Execute a command (this enables commands to call other commands).
71
- # @param [String] name The command to execute
72
- # @param [Array] args The parameters to pass to the command.
73
- # @example Wrap one command with another
74
- # class MyCommands < Pry::Commands
75
- # command "ls2" do
76
- # output.puts "before ls"
77
- # run "ls"
78
- # output.puts "after ls"
79
- # end
80
- # end
81
- def run(name, *args)
82
- action = opts[:commands][name][:action]
83
- instance_exec(*args, &action)
84
- end
85
-
86
- # Import commands from another command object.
87
- # @param [Pry::CommandBase] klass The class to import from (must
88
- # be a subclass of `Pry::CommandBase`)
89
- # @param [Array<String>] names The commands to import.
90
- # @example
91
- # class MyCommands < Pry::CommandBase
92
- # import_from Pry::Commands, "ls", "show_method", "cd"
93
- # end
94
- def import_from(klass, *names)
95
- imported_hash = Hash[klass.commands.select { |k, v| names.include?(k) }]
96
- commands.merge!(imported_hash)
97
- end
98
-
99
- # Create an alias for a command.
100
- # @param [String] new_command The alias name.
101
- # @param [String] orig_command The original command name.
102
- # @param [String] desc The optional description.
103
- # @example
104
- # class MyCommands < Pry::CommandBase
105
- # alias_command "help_alias", "help"
106
- # end
107
- def alias_command(new_command_name, orig_command_name, desc=nil)
108
- commands[new_command_name] = commands[orig_command_name].dup
109
- commands[new_command_name][:description] = desc if desc
110
- end
111
-
112
- # Set the description for a command (replacing the old
113
- # description.)
114
- # @param [String] name The command name.
115
- # @param [String] description The command description.
116
- # @example
117
- # class MyCommands < Pry::CommandBase
118
- # desc "help", "help description"
119
- # end
120
- def desc(name, description)
121
- commands[name][:description] = description
122
- end
123
- end
124
-
125
- command "help", "This menu." do |cmd|
126
- command_info = opts[:commands]
127
- param = cmd
128
-
129
- if !param
130
- output.puts "Command list:"
131
- output.puts "--"
132
- command_info.each do |k, data|
133
- output.puts "#{k}".ljust(18) + data[:description] if !data[:description].empty?
134
- end
135
- else
136
- if command_info[param]
137
- output.puts command_info[param][:description]
138
- else
139
- output.puts "No info for command: #{param}"
140
- end
141
- end
142
- end
143
-
144
- # Ensures that commands can be inherited
145
- def self.inherited(klass)
146
- klass.commands = commands.dup
147
- end
148
-
149
- end
150
- end
1
+ class Pry
2
+
3
+ # Basic command functionality. All user-defined commands must
4
+ # inherit from this class. It provides the `command` method.
5
+ class CommandBase
6
+ class << self
7
+ attr_accessor :commands
8
+ attr_accessor :opts, :output, :target
9
+
10
+ # private because we want to force function style invocation. We require
11
+ # that the location where the block is defined has the `opts`
12
+ # method in scope.
13
+ private
14
+
15
+ # Defines a new Pry command.
16
+ # @param [String, Array] names The name of the command (or array of
17
+ # command name aliases).
18
+ # @param [String] description A description of the command.
19
+ # @param [Hash] options The optional configuration parameters.
20
+ # @option options [Boolean] :keep_retval Whether or not to use return value
21
+ # of the block for return of `command` or just to return `nil`
22
+ # (the default).
23
+ # @yield The action to perform. The parameters in the block
24
+ # determines the parameters the command will receive. All
25
+ # parameters passed into the block will be strings. Successive
26
+ # command parameters are separated by whitespace at the Pry prompt.
27
+ # @example
28
+ # class MyCommands < Pry::CommandBase
29
+ # command "greet", "Greet somebody" do |name|
30
+ # puts "Good afternoon #{name.capitalize}!"
31
+ # end
32
+ # end
33
+ #
34
+ # # From pry:
35
+ # # pry(main)> _pry_.commands = MyCommands
36
+ # # pry(main)> greet john
37
+ # # Good afternoon John!
38
+ # # pry(main)> help greet
39
+ # # Greet somebody
40
+ def command(names, description="No description.", options={}, &block)
41
+ options = {
42
+ :keep_retval => false
43
+ }.merge!(options)
44
+
45
+ @commands ||= {}
46
+
47
+ Array(names).each do |name|
48
+ commands[name] = {
49
+ :description => description,
50
+ :action => block,
51
+ :keep_retval => options[:keep_retval]
52
+ }
53
+ end
54
+ end
55
+
56
+ # Delete a command or an array of commands.
57
+ # Useful when inheriting from another command set and pruning
58
+ # those commands down to the ones you want.
59
+ # @param [Array<String>] names The command name or array
60
+ # of command names you want to delete
61
+ # @example Deleteing inherited commands
62
+ # class MyCommands < Pry::Commands
63
+ # delete "show_method", "show_imethod", "show_doc", "show_idoc"
64
+ # end
65
+ # Pry.commands = MyCommands
66
+ def delete(*names)
67
+ names.each { |name| commands.delete(name) }
68
+ end
69
+
70
+ # Execute a command (this enables commands to call other commands).
71
+ # @param [String] name The command to execute
72
+ # @param [Array] args The parameters to pass to the command.
73
+ # @example Wrap one command with another
74
+ # class MyCommands < Pry::Commands
75
+ # command "ls2" do
76
+ # output.puts "before ls"
77
+ # run "ls"
78
+ # output.puts "after ls"
79
+ # end
80
+ # end
81
+ def run(name, *args)
82
+ action = opts[:commands][name][:action]
83
+ instance_exec(*args, &action)
84
+ end
85
+
86
+ # Import commands from another command object.
87
+ # @param [Pry::CommandBase] klass The class to import from (must
88
+ # be a subclass of `Pry::CommandBase`)
89
+ # @param [Array<String>] names The commands to import.
90
+ # @example
91
+ # class MyCommands < Pry::CommandBase
92
+ # import_from Pry::Commands, "ls", "show_method", "cd"
93
+ # end
94
+ def import_from(klass, *names)
95
+ imported_hash = Hash[klass.commands.select { |k, v| names.include?(k) }]
96
+ commands.merge!(imported_hash)
97
+ end
98
+
99
+ # Create an alias for a command.
100
+ # @param [String] new_command The alias name.
101
+ # @param [String] orig_command The original command name.
102
+ # @param [String] desc The optional description.
103
+ # @example
104
+ # class MyCommands < Pry::CommandBase
105
+ # alias_command "help_alias", "help"
106
+ # end
107
+ def alias_command(new_command_name, orig_command_name, desc=nil)
108
+ commands[new_command_name] = commands[orig_command_name].dup
109
+ commands[new_command_name][:description] = desc if desc
110
+ end
111
+
112
+ # Set the description for a command (replacing the old
113
+ # description.)
114
+ # @param [String] name The command name.
115
+ # @param [String] description The command description.
116
+ # @example
117
+ # class MyCommands < Pry::CommandBase
118
+ # desc "help", "help description"
119
+ # end
120
+ def desc(name, description)
121
+ commands[name][:description] = description
122
+ end
123
+ end
124
+
125
+ command "help", "This menu." do |cmd|
126
+ command_info = opts[:commands]
127
+ param = cmd
128
+
129
+ if !param
130
+ output.puts "Command list:"
131
+ output.puts "--"
132
+ command_info.each do |k, data|
133
+ output.puts "#{k}".ljust(18) + data[:description] if !data[:description].empty?
134
+ end
135
+ else
136
+ if command_info[param]
137
+ output.puts command_info[param][:description]
138
+ else
139
+ output.puts "No info for command: #{param}"
140
+ end
141
+ end
142
+ end
143
+
144
+ # Ensures that commands can be inherited
145
+ def self.inherited(klass)
146
+ klass.commands = commands.dup
147
+ end
148
+
149
+ end
150
+ end