2013-12-17 12:27:42 -05:00
|
|
|
class Pry::Config
|
|
|
|
require 'ostruct'
|
|
|
|
require 'pry/config/default'
|
|
|
|
require 'pry/config/convenience'
|
2014-01-20 07:27:16 -05:00
|
|
|
ASSIGNMENT = "=".freeze
|
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 = {}
|
|
|
|
end
|
2013-04-25 08:29:26 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def [](key)
|
2014-01-20 06:34:34 -05:00
|
|
|
@lookup[key.to_s]
|
2013-12-17 12:27:42 -05:00
|
|
|
end
|
2011-10-16 02:49:33 -04:00
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def []=(key, value)
|
2014-01-20 06:34:34 -05:00
|
|
|
@lookup[key.to_s] = value
|
2013-12-17 12:27:42 -05:00
|
|
|
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-20 07:27:16 -05:00
|
|
|
if key[-1] == ASSIGNMENT
|
2014-01-20 07:51:52 -05:00
|
|
|
short_key = key[0..-2]
|
2014-01-20 06:39:56 -05:00
|
|
|
self[short_key] = args[0]
|
2014-01-18 22:12:39 -05:00
|
|
|
elsif @lookup.has_key?(key)
|
2014-01-20 06:39:56 -05:00
|
|
|
self[key]
|
2013-12-17 12:27:42 -05:00
|
|
|
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-20 07:00:28 -05:00
|
|
|
raise TypeError, "cannot coerce argument to Hash" unless other.respond_to?(:to_hash)
|
2014-01-20 02:40:05 -05:00
|
|
|
other = other.to_hash
|
|
|
|
keys, values = other.keys.map(&:to_s), other.values
|
|
|
|
@lookup.merge! Hash[keys.zip(values)]
|
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
|
2014-01-20 07:51:52 -05:00
|
|
|
@lookup
|
2014-01-18 22:21:22 -05:00
|
|
|
end
|
|
|
|
|
2013-12-17 12:27:42 -05:00
|
|
|
def quiet?
|
|
|
|
quiet
|
|
|
|
end
|
2011-05-28 04:43:32 -04:00
|
|
|
end
|