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

add Behavior#inherited_by and Behavior#wipe!.

many TODO's to clean up.
This commit is contained in:
Robert Gleeson 2014-01-27 06:00:29 +01:00
parent 283b85c9a1
commit 6ec7649813
2 changed files with 23 additions and 14 deletions

View file

@ -1,10 +1,10 @@
module Pry::Config::Behavior
ASSIGNMENT = "=".freeze
NODUP = [TrueClass, FalseClass, NilClass, String, Module, Proc, Numeric].freeze
NODUP = [TrueClass, FalseClass, NilClass, Module, Proc, Numeric].freeze
def initialize(default = Pry.config)
@default = default
@default._register(self) if @default
@default.inherited_by(self) if @default
@lookup = {}
@read_lookup = {}
end
@ -20,8 +20,8 @@ module Pry::Config::Behavior
def method_missing(name, *args, &block)
key = name.to_s
if key[-1] == ASSIGNMENT
@inherited_by.wipe!(short_key) if @inherited_by
short_key = key[0..-2]
@default._forget(short_key) if @default
self[short_key] = args[0]
elsif @lookup.has_key?(key)
self[key]
@ -43,18 +43,35 @@ module Pry::Config::Behavior
end
def respond_to?(name, boolean=false)
@lookup.has_key?(name.to_s) or @default.respond_to?(name) or super(name, boolean)
@lookup.has_key?(name.to_s) or @read_lookup.has_key?(name.to_s) or @default.respond_to?(name) or super(name, boolean)
end
def refresh
@lookup = {}
def wipe!(key = nil)
if key == nil
@lookup = {}
@read_lookup = {}
else
@lookup.delete(key)
@read_lookup.delete(key)
end
end
def inherited_by(other)
if @inherited_by
# TODO
raise
else
@inherited_by = other
end
end
def to_hash
# TODO: should merge read_lookup?
@lookup
end
def to_h
# TODO: should merge read_lookup?
@lookup
end

View file

@ -51,14 +51,6 @@ class Pry::Config::Default
configure_history
end
def _register(other)
@child = other
end
def _forget(key)
@child.instance_variable_get(:@read_lookup).delete(key.to_s)
end
default.each do |key, value|
define_method(key) do
if default[key].equal?(value)