Skip to content

Commit

Permalink
Added alias to_h for to_hash (rubyconfig#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneGod authored Jun 6, 2020
1 parent b868f89 commit 4b65ca6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug fixes

* Added alias to_h for to_hash ([#277](https://github.com/railsconfig/config/issues/277))

### Changes

* Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228))
Expand Down
2 changes: 2 additions & 0 deletions lib/config/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def to_hash
result
end

alias :to_h :to_hash

def each(*args, &block)
marshal_dump.each(*args, &block)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
expect(config[:section][:servers][1]).to be_kind_of(Config::Options)
end

it "should convert to a hash without modifying nested settings" do
config = Config.load_files("#{fixture_path}/development.yml")
config.to_h
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

0 comments on commit 4b65ca6

Please sign in to comment.