2010-12-29 09:14:12 +00:00
|
|
|
# @author John Mair (banisterfiend)
|
2010-12-25 13:59:37 +00:00
|
|
|
class Pry
|
|
|
|
|
|
|
|
# class accessors
|
|
|
|
class << self
|
2010-12-29 09:14:12 +00:00
|
|
|
|
|
|
|
# Get nesting data.
|
|
|
|
# This method should not need to be accessed directly.
|
|
|
|
# @return [Array] The unparsed nesting information.
|
2010-12-25 13:59:37 +00:00
|
|
|
attr_reader :nesting
|
2010-12-29 09:14:12 +00:00
|
|
|
|
|
|
|
# Get last value evaluated by Pry.
|
|
|
|
# This method should not need to be accessed directly.
|
|
|
|
# @return [Object] The last result.
|
|
|
|
attr_accessor :last_result
|
|
|
|
|
|
|
|
# Get the active Pry instance that manages the active Pry session.
|
|
|
|
# This method should not need to be accessed directly.
|
|
|
|
# @return [Pry] The active Pry instance.
|
|
|
|
attr_accessor :active_instance
|
|
|
|
|
|
|
|
# Set/Get the object to use for input by default by all Pry instances.
|
|
|
|
# (see input.rb)
|
|
|
|
# @return [#read] The object to use for input by default by all
|
|
|
|
# Pry instances.
|
|
|
|
attr_accessor :input
|
|
|
|
|
|
|
|
# Set/Get the object to use for output by default by all Pry instances.
|
|
|
|
# (see: output.rb)
|
|
|
|
# @return [#puts] The object to use for output by default by all
|
|
|
|
# Pry instances.
|
|
|
|
attr_accessor :output
|
|
|
|
|
|
|
|
# Set/Get the object to use for commands by default by all Pry instances.
|
|
|
|
# (see commands.rb)
|
|
|
|
# @return [#commands] The object to use for commands by default by all
|
|
|
|
# Pry instances.
|
|
|
|
attr_accessor :commands
|
|
|
|
|
|
|
|
# Set/Get the Proc to use for printing by default by all Pry
|
|
|
|
# instances.
|
|
|
|
# This is the 'print' componenent of the REPL.
|
|
|
|
# (see print.rb)
|
|
|
|
# @return [Proc] The Proc to use for printing by default by all
|
|
|
|
# Pry instances.
|
|
|
|
attr_accessor :print
|
|
|
|
|
|
|
|
|
|
|
|
# Set/Get the Hash that defines Pry hooks used by default by all Pry
|
|
|
|
# instances.
|
|
|
|
# (see print.rb)
|
|
|
|
# @return [Hash] The hooks used by default by all Pry instances.
|
|
|
|
# @example
|
|
|
|
# Pry.hooks :before_session => proc { puts "hello" },
|
|
|
|
# :after_session => proc { puts "goodbye" }
|
|
|
|
attr_accessor :hooks
|
|
|
|
|
|
|
|
# Set/Get the array of Procs to be used for the prompts by default by
|
|
|
|
# all Pry instances.
|
|
|
|
# (see prompts.rb)
|
|
|
|
# @return [Array<Proc>] The array of Procs to be used for the
|
|
|
|
# prompts by default by all Pry instances.
|
2010-12-27 12:36:29 +00:00
|
|
|
attr_accessor :default_prompt
|
2010-12-25 13:59:37 +00:00
|
|
|
end
|
2010-12-28 03:56:23 +00:00
|
|
|
|
2010-12-29 09:14:12 +00:00
|
|
|
# Start a Pry REPL.
|
|
|
|
# @param [Object, Binding] target The receiver of the Pry session
|
|
|
|
# @param options (see Pry#initialize)
|
|
|
|
# @example
|
|
|
|
# Pry.start(Object.new, :input => MyInput.new)
|
2010-12-25 13:59:37 +00:00
|
|
|
def self.start(target=TOPLEVEL_BINDING, options={})
|
|
|
|
new(options).repl(target)
|
|
|
|
end
|
|
|
|
|
2010-12-29 09:14:12 +00:00
|
|
|
# A custom version of `Kernel#inspect`.
|
|
|
|
# This method should not need to be accessed directly.
|
|
|
|
# @param obj The object to view.
|
|
|
|
# @return [String] The string representation of `obj`.
|
2010-12-25 13:59:37 +00:00
|
|
|
def self.view(obj)
|
|
|
|
case obj
|
2010-12-27 12:36:29 +00:00
|
|
|
when String, Hash, Array, Symbol, nil
|
2010-12-25 13:59:37 +00:00
|
|
|
obj.inspect
|
|
|
|
else
|
|
|
|
obj.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-29 09:14:12 +00:00
|
|
|
# Set all the configurable options back to their default values
|
2010-12-25 13:59:37 +00:00
|
|
|
def self.reset_defaults
|
2010-12-25 14:18:30 +00:00
|
|
|
@input = Input.new
|
|
|
|
@output = Output.new
|
2010-12-26 13:39:46 +00:00
|
|
|
@commands = Commands.new(@output)
|
2010-12-28 03:56:23 +00:00
|
|
|
@default_prompt = STANDARD_PROMPT
|
2010-12-27 10:56:55 +00:00
|
|
|
@print = DEFAULT_PRINT
|
|
|
|
@hooks = DEFAULT_HOOKS
|
2010-12-25 13:59:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.reset_defaults
|
|
|
|
|
|
|
|
@nesting = []
|
|
|
|
def @nesting.level
|
|
|
|
last.is_a?(Array) ? last.first : nil
|
|
|
|
end
|
|
|
|
end
|