mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
change from_hash to be recursive.
This commit is contained in:
parent
8a932c7b7e
commit
46f24c3f77
2 changed files with 16 additions and 1 deletions
|
@ -17,7 +17,9 @@ module Pry::Config::Behavior
|
|||
#
|
||||
def from_hash(attributes, default = nil)
|
||||
new(default).tap do |config|
|
||||
config.merge!(attributes)
|
||||
attributes.each do |key,value|
|
||||
config[key] = Hash === value ? from_hash(value, nil) : value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,6 +57,19 @@ describe Pry::Config do
|
|||
local = Pry::Config.from_hash({}, default)
|
||||
expect(local.default).to eq(local)
|
||||
end
|
||||
|
||||
it "recursively builds Pry::Config objects from a Hash" do
|
||||
h = {
|
||||
'foo1' => {
|
||||
'foo2' => {
|
||||
'foo3' => 'foobar'
|
||||
}
|
||||
}
|
||||
}
|
||||
default = Pry::Config.from_hash(h)
|
||||
expect(default.foo1).to be_instance_of(described_class)
|
||||
expect(default.foo1.foo2).to be_instance_of(described_class)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue