This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#544) Improve backward compatibility in JSON mode
This create a Hash variant that allow :x to access "x" if :x does not exist, it uses this in the JSON deserialize to improve backwards compat for the old hashes that was in yaml With this code in place `mco facts` works again unmodified
- Loading branch information
Showing
4 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module MCollective | ||
module Util | ||
class IndifferentHash < Hash | ||
def [](key) | ||
return super if key?(key) | ||
return self[key.to_s] if key.is_a?(Symbol) | ||
|
||
super | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "spec_helper" | ||
require "mcollective/util/indifferent_hash" | ||
|
||
module MCollective | ||
module Util | ||
describe IndifferentHash do | ||
describe "#[]" do | ||
it "should correctly grant indifferent access" do | ||
h = IndifferentHash["x" => "y"] | ||
expect(h[:x]).to eq("y") | ||
expect(h["x"]).to eq("y") | ||
|
||
h = IndifferentHash[:x => "y"] | ||
expect(h[:x]).to eq("y") | ||
expect(h["x"]).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |