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:
parent
44463e7d85
commit
2202ab775c
2 changed files with 5 additions and 20 deletions
|
@ -19,11 +19,7 @@ module Pry::Config::Behavior
|
|||
end
|
||||
|
||||
def initialize(default = Pry.config)
|
||||
if default
|
||||
@default = default.dup
|
||||
@default.default_for(self)
|
||||
end
|
||||
@default_for = nil
|
||||
@default = default
|
||||
@lookup = {}
|
||||
end
|
||||
|
||||
|
@ -56,7 +52,10 @@ module Pry::Config::Behavior
|
|||
self[key]
|
||||
elsif @default.respond_to?(name)
|
||||
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
|
||||
nil
|
||||
end
|
||||
|
@ -94,14 +93,6 @@ module Pry::Config::Behavior
|
|||
@lookup.delete(key.to_s)
|
||||
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
|
||||
@lookup.keys
|
||||
end
|
||||
|
|
|
@ -21,12 +21,6 @@ describe Pry::Config do
|
|||
local.foo.should == 2
|
||||
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
|
||||
root = Pry::Config.from_hash({foo: 21})
|
||||
local1 = Pry::Config.new(root)
|
||||
|
|
Loading…
Reference in a new issue