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

Move to a fall-through config hash.

This is somewhat easier to understand than the current solution,
but does have some downsides: namely it doesn't work for things like
Pry::Hooks.

It is however the only way I've thought of to let setting
Pry.config.color = work in addition to _pry.config.color =.

For now I've added a hack so that hooks work as they did before,
in future we should work out how to fix them so that only the data
for hooks is stored in the config object, not the hooks object itself.
This commit is contained in:
Conrad Irwin 2014-04-30 00:51:59 -07:00
parent 44463e7d85
commit 2202ab775c
2 changed files with 5 additions and 20 deletions

View file

@ -19,11 +19,7 @@ module Pry::Config::Behavior
end end
def initialize(default = Pry.config) def initialize(default = Pry.config)
if default @default = default
@default = default.dup
@default.default_for(self)
end
@default_for = nil
@lookup = {} @lookup = {}
end end
@ -56,7 +52,10 @@ module Pry::Config::Behavior
self[key] self[key]
elsif @default.respond_to?(name) elsif @default.respond_to?(name)
value = @default.public_send(name, *args, &block) value = @default.public_send(name, *args, &block)
self[key] = _dup(value) # FIXME: refactor Pry::Hook so that it stores config on the config object,
# so that we can use the normal strategy.
self[key] = value.dup if key == 'hooks'
value
else else
nil nil
end end
@ -94,14 +93,6 @@ module Pry::Config::Behavior
@lookup.delete(key.to_s) @lookup.delete(key.to_s)
end end
def default_for(other)
if @default_for
raise RuntimeError, "self is already the default for %s" % _clip_inspect(@default_for)
else
@default_for = other
end
end
def keys def keys
@lookup.keys @lookup.keys
end end

View file

@ -21,12 +21,6 @@ describe Pry::Config do
local.foo.should == 2 local.foo.should == 2
end end
it "duplicates a copy on read from the parent" do
ukraine = "i love"
local = Pry::Config.new Pry::Config.from_hash(home: ukraine)
local.home.equal?(ukraine).should == false
end
it "traverses through a chain of parents" do it "traverses through a chain of parents" do
root = Pry::Config.from_hash({foo: 21}) root = Pry::Config.from_hash({foo: 21})
local1 = Pry::Config.new(root) local1 = Pry::Config.new(root)