Skip to content

Commit d2c5356

Browse files
authored
Added alias to_h for to_hash (#297)
1 parent 637f32c commit d2c5356

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
## Unreleased
44

5-
...
5+
### BREAKING CHANGES
6+
7+
After upgrade behaviour of `to_h` would change and match behaviour of `to_hash`. Check [#217](https://github.com/rubyconfig/config/issues/217#issuecomment-741953382) for more details.
8+
9+
### Bug fixes
10+
11+
* Added alias `to_h` for `to_hash` ([#277](https://github.com/railsconfig/config/issues/277))
612

713
## 2.2.3
814

lib/config/options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def to_hash
123123
result
124124
end
125125

126+
alias :to_h :to_hash
127+
126128
def each(*args, &block)
127129
marshal_dump.each(*args, &block)
128130
end

spec/config_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@
8080
expect(config[:section][:servers][1]).to be_kind_of(Config::Options)
8181
end
8282

83+
it "should convert to a hash without modifying nested settings" do
84+
config = Config.load_files("#{fixture_path}/development.yml")
85+
config.to_h
86+
expect(config).to be_kind_of(Config::Options)
87+
expect(config[:section]).to be_kind_of(Config::Options)
88+
expect(config[:section][:servers][0]).to be_kind_of(Config::Options)
89+
expect(config[:section][:servers][1]).to be_kind_of(Config::Options)
90+
end
91+
8392
it "should convert to a json" do
8493
config = Config.load_files("#{fixture_path}/development.yml").to_json
8594
expect(JSON.parse(config)["section"]["servers"]).to be_kind_of(Array)

0 commit comments

Comments
 (0)