2013-12-17 12:27:42 -05:00
|
|
|
class Pry::Config
|
|
|
|
require 'ostruct'
|
|
|
|
require 'pry/config/default'
|
|
|
|
require 'pry/config/convenience'
|
2011-05-28 04:43:32 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def self.shortcuts
|
|
|
|
Convenience::SHORTCUTS
|
|
|
|
end
|
2011-09-17 21:45:46 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def initialize(default = Pry.config)
|
|
|
|
@default = default
|
|
|
|
@lookup = {}
|
|
|
|
configure_gist
|
|
|
|
configure_ls
|
|
|
|
configure_history
|
|
|
|
end
|
2013-04-25 08:29:26 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def [](key)
|
|
|
|
@lookup[key]
|
|
|
|
end
|
2011-10-16 02:49:33 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def []=(key, value)
|
|
|
|
@lookup[key] = value
|
|
|
|
end
|
2012-01-23 07:10:51 -05:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def method_missing(name, *args, &block)
|
|
|
|
key = name.to_s
|
2014-01-18 22:12:39 -05:00
|
|
|
if key[-1] == "="
|
|
|
|
short_key = key.to_s[0..-2]
|
|
|
|
@lookup[short_key] = args[0]
|
|
|
|
elsif @lookup.has_key?(key)
|
2013-12-17 12:27:42 -05:00
|
|
|
@lookup[key]
|
|
|
|
elsif @default.respond_to?(name)
|
|
|
|
@default.public_send(name, *args, &block)
|
|
|
|
else
|
|
|
|
nil
|
2012-01-23 07:10:51 -05:00
|
|
|
end
|
2013-12-17 12:27:42 -05:00
|
|
|
end
|
2011-05-28 04:43:32 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def merge!(other)
|
2014-01-18 22:21:22 -05:00
|
|
|
@lookup.merge!(other.to_hash)
|
2013-12-17 12:27:42 -05:00
|
|
|
end
|
2011-10-05 13:04:44 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def respond_to?(name, boolean=false)
|
|
|
|
@lookup.has_key?(name.to_s) or @default.respond_to?(name) or super(name, boolean)
|
|
|
|
end
|
2011-10-28 02:57:01 -04:00
|
|
|
|
2014-01-18 21:37:57 -05:00
|
|
|
def refresh
|
|
|
|
@lookup = {}
|
|
|
|
end
|
|
|
|
|
2014-01-18 22:21:22 -05:00
|
|
|
def to_hash
|
2013-12-17 12:27:42 -05:00
|
|
|
@lookup
|
|
|
|
end
|
2011-11-16 22:00:46 -05:00
|
|
|
|
2014-01-18 22:21:22 -05:00
|
|
|
def to_h
|
|
|
|
to_hash
|
|
|
|
end
|
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def quiet?
|
|
|
|
quiet
|
|
|
|
end
|
2011-12-11 03:16:09 -05:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
private
|
|
|
|
# TODO:
|
|
|
|
# all of this configure_* stuff is a relic of old code.
|
|
|
|
# we should try move this code to being command-local.
|
|
|
|
def configure_ls
|
|
|
|
@lookup["ls"] = OpenStruct.new({
|
|
|
|
:heading_color => :bright_blue,
|
|
|
|
:public_method_color => :default,
|
|
|
|
:private_method_color => :blue,
|
|
|
|
:protected_method_color => :blue,
|
|
|
|
:method_missing_color => :bright_red,
|
|
|
|
:local_var_color => :yellow,
|
|
|
|
:pry_var_color => :default, # e.g. _, _pry_, _file_
|
|
|
|
:instance_var_color => :blue, # e.g. @foo
|
|
|
|
:class_var_color => :bright_blue, # e.g. @@foo
|
|
|
|
:global_var_color => :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
|
|
|
|
:builtin_global_color => :cyan, # e.g. $stdin, $-w, $PID
|
|
|
|
:pseudo_global_color => :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
|
|
|
|
:constant_color => :default, # e.g. VERSION, ARGF
|
|
|
|
:class_constant_color => :blue, # e.g. Object, Kernel
|
|
|
|
:exception_constant_color => :magenta, # e.g. Exception, RuntimeError
|
|
|
|
:unloaded_constant_color => :yellow, # Any constant that is still in .autoload? state
|
|
|
|
:separator => " ",
|
|
|
|
:ceiling => [Object, Module, Class]
|
|
|
|
})
|
|
|
|
end
|
2012-03-13 22:33:51 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def configure_gist
|
|
|
|
@lookup["gist"] = OpenStruct.new
|
|
|
|
gist.inspecter = proc(&:pretty_inspect)
|
|
|
|
end
|
2012-08-18 18:49:20 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def configure_history
|
|
|
|
@lookup["history"] = OpenStruct.new
|
|
|
|
history.should_save = true
|
|
|
|
history.should_load = true
|
|
|
|
history.file = File.expand_path("~/.pry_history") rescue nil
|
|
|
|
if history.file.nil?
|
|
|
|
self.should_load_rc = false
|
|
|
|
history.should_save = false
|
|
|
|
history.should_load = false
|
|
|
|
end
|
2011-05-28 04:43:32 -04:00
|
|
|
end
|
|
|
|
end
|