Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
Fix: remove empty hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jan 14, 2016
1 parent 097543e commit 2b7d9a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion libraries/mongodb3_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ def mongodb_config(config)
class Hash
def compact
inject({}) do |new_hash, (k, v)|
new_hash[k] = v.is_a?(Hash) ? v.compact : v unless v.nil?
if v.is_a?(Hash)
v = v.compact
new_hash[k] = v unless v.empty?
else
new_hash[k] = v unless v.nil?
end
new_hash
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/mongodb3_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end
end
context '#mongodb_config' do
let(:config) { Chef::Node::ImmutableMash.new('systemLog' => { 'verbosity' => nil, 'path' => '/var/log' }) }
let(:config) { Chef::Node::ImmutableMash.new('systemLog' => { 'verbosity' => nil, 'path' => '/var/log', 'empty' => { 'foo' => nil } }) }
it 'with an immutable Mash' do
expect(YAML.load(subject.mongodb_config(config))).to eq('systemLog' => { 'path' => '/var/log' })
end
Expand Down

1 comment on commit 2b7d9a3

@Gopalvisualpath
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, when ever i pass input in bindip like [10.10.0.10,127.0.0.1] for mongos template, the output file is generating error
PFB out put - net:
port: 27017
bindIp: ! '[10.10.0.10,127.0.0.1]'
getting ! and '' beside to square brackets,
can you please help on this ?

Please sign in to comment.