Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Structures should handle UNSET_VALUE merging
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Apr 9, 2012
1 parent 94631fb commit 3016e04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/omniconfig/structure.rb
Expand Up @@ -106,6 +106,12 @@ def value(raw)
# The merge behavior for a structure is to do a deep merge, merging each
# individual field within.
def merge(old, new)
# We don't need to merge if one of the values is unset, since that is
# pretty straightforward.
return new if old == UNSET_VALUE
return old if new == UNSET_VALUE

# Merge member by member
result = {}
@members.each do |key, type|
if old.has_key?(key) && !new.has_key?(key)
Expand Down
8 changes: 8 additions & 0 deletions spec/omniconfig/structure_spec.rb
Expand Up @@ -90,5 +90,13 @@
result = instance.merge(old, new)
result["foo"].should == 5
end

it "should take the new value if the old one is UNSET" do
instance.merge(OmniConfig::UNSET_VALUE, 5).should == 5
end

it "should take the old value if the new one is UNSET" do
instance.merge(2, OmniConfig::UNSET_VALUE).should == 2
end
end
end

0 comments on commit 3016e04

Please sign in to comment.