# File lib/pry/config/behavior.rb, line 14 def self.included(klass) unless defined?(RESERVED_KEYS) const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze end klass.extend(Builder) end
# File lib/pry/config/behavior.rb, line 21 def initialize(default = Pry.config) @default = default @lookup = {} end
# File lib/pry/config/behavior.rb, line 72 def ==(other) @lookup == try_convert_to_hash(other) end
# File lib/pry/config/behavior.rb, line 34 def [](key) @lookup[key.to_s] end
# File lib/pry/config/behavior.rb, line 38 def []=(key, value) key = key.to_s if RESERVED_KEYS.include?(key) raise ArgumentError, "few things are reserved by pry, but using '#{key}' as a configuration key is." end @lookup[key] = value end
# File lib/pry/config/behavior.rb, line 86 def clear @lookup.clear true end
@return [Pry::Config::Behavior]
returns the default used if a matching value for a key isn't found in self
# File lib/pry/config/behavior.rb, line 30 def default @default end
# File lib/pry/config/behavior.rb, line 92 def forget(key) @lookup.delete(key.to_s) end
# File lib/pry/config/behavior.rb, line 106 def inspect key_str = keys.map { |key| "'#{key}'" }.join(",") "#<#{_clip_inspect(self)} local_keys=[#{key_str}] default=#{@default.inspect}>" end
# File lib/pry/config/behavior.rb, line 81 def key?(key) key = key.to_s @lookup.key?(key) end
# File lib/pry/config/behavior.rb, line 96 def keys @lookup.keys end
# File lib/pry/config/behavior.rb, line 64 def merge!(other) other = try_convert_to_hash(other) raise TypeError, "unable to convert argument into a Hash" unless other other.each do |key, value| self[key] = value end end
# File lib/pry/config/behavior.rb, line 46 def method_missing(name, *args, &block) key = name.to_s if key[-1] == ASSIGNMENT short_key = key[0..-2] self[short_key] = args[0] elsif key?(key) self[key] elsif @default.respond_to?(name) value = @default.public_send(name, *args, &block) # FIXME: refactor Pry::Hook so that it stores config on the config object, # so that we can use the normal strategy. self[key] = value = value.dup if key == 'hooks' value else nil end end
# File lib/pry/config/behavior.rb, line 111 def pretty_print(q) q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<") end
# File lib/pry/config/behavior.rb, line 77 def respond_to_missing?(key, include_private=false) key?(key) or @default.respond_to?(key) or super(key, include_private) end
# File lib/pry/config/behavior.rb, line 100 def to_hash @lookup.dup end