1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/config.rb

65 lines
1.2 KiB
Ruby
Raw Normal View History

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
def self.shortcuts
Convenience::SHORTCUTS
end
def initialize(default = Pry.config)
@default = default
@lookup = {}
end
def [](key)
@lookup[key.to_s]
end
def []=(key, value)
@lookup[key.to_s] = value
end
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]
self[short_key] = args[0]
elsif @lookup.has_key?(key)
self[key]
elsif @default.respond_to?(name)
@default.public_send(name, *args, &block)
else
nil
end
end
2011-05-28 04:43:32 -04:00
def merge!(other)
raise TypeError, "cannot coerce argument to Hash" unless other.respond_to?(:to_hash)
other = other.to_hash
keys, values = other.keys.map(&:to_s), other.values
@lookup.merge! Hash[keys.zip(values)]
end
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
def to_hash
@lookup
end
def to_h
2014-01-20 07:51:52 -05:00
@lookup
end
def quiet?
quiet
end
2011-05-28 04:43:32 -04:00
end