diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2014-04-30 00:51:59 -0700 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2014-05-01 01:51:01 -0700 |
commit | 2202ab775c635f8b7a3c244266365d442e9ceaec (patch) | |
tree | 97f05824fe8fe75bade24daeb80f803408afeab0 | |
parent | 44463e7d85a8212b1b4c6298ecface4783824847 (diff) | |
download | pry-2202ab775c635f8b7a3c244266365d442e9ceaec.tar.gz |
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.
-rw-r--r-- | lib/pry/config/behavior.rb | 19 | ||||
-rw-r--r-- | spec/config_spec.rb | 6 |
2 files changed, 5 insertions, 20 deletions
diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb index 9b5c42ae..1cb98da5 100644 --- a/lib/pry/config/behavior.rb +++ b/lib/pry/config/behavior.rb @@ -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 diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 0652619d..228f30dc 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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) |