Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#to_hash should not replace nested config objects with Hash #160

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/config/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def []=(param, value)
protected

def descend_array(array)
array.length.times do |i|
value = array[i]
array.map do |value|
if value.instance_of? Config::Options
array[i] = value.to_hash
value.to_hash
elsif value.instance_of? Array
array[i] = descend_array(value)
descend_array(value)
else
value
end
end
array
end

# Recursively converts Hashes to Options (including Hashes inside Arrays)
Expand Down
9 changes: 9 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
expect(servers).to eq([{ name: "yahoo.com" }, { name: "amazon.com" }])
end

it "should convert to a hash without modifying nested settings" do
config = Config.load_files("#{fixture_path}/development.yml")
config.to_hash
expect(config).to be_kind_of(Config::Options)
expect(config[:section]).to be_kind_of(Config::Options)
expect(config[:section][:servers][0]).to be_kind_of(Config::Options)
expect(config[:section][:servers][1]).to be_kind_of(Config::Options)
end

it "should convert to a json" do
config = Config.load_files("#{fixture_path}/development.yml").to_json
expect(JSON.parse(config)["section"]["servers"]).to be_kind_of(Array)
Expand Down