hashie 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hashie/hash.rb +3 -1
- data/lib/hashie/version.rb +1 -1
- data/spec/hashie/mash_spec.rb +7 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1308b1b5e87e1b28328361a0b2f2d084839e7864
|
4
|
+
data.tar.gz: 2db28fef4c8dc89369658de62b59e046e2076ddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fa20289e9e8a0c57737ed4b79f3c7ea95dd907b8ce5912e75448b1dfe99b4df8b0197bc3719d0ba9db4f995d9d6492cd1a2d0bd0cd1dba748c14d209d4823db
|
7
|
+
data.tar.gz: 838e995acf432ebf669768a68d62797c601823ea521a93b448a584ecf9257323376c1632b5c45e324e2ced4a06265e27417fae15d189ecb8f0e8692a7ba9ad3b
|
data/lib/hashie/hash.rb
CHANGED
@@ -8,15 +8,17 @@ module Hashie
|
|
8
8
|
include HashExtensions
|
9
9
|
|
10
10
|
# Converts a mash back to a hash (with stringified keys)
|
11
|
-
def to_hash
|
11
|
+
def to_hash(options={})
|
12
12
|
out = {}
|
13
13
|
keys.each do |k|
|
14
14
|
if self[k].is_a?(Array)
|
15
|
+
k = options[:symbolize_keys] ? k.to_sym : k.to_s
|
15
16
|
out[k] ||= []
|
16
17
|
self[k].each do |array_object|
|
17
18
|
out[k] << (Hash === array_object ? array_object.to_hash : array_object)
|
18
19
|
end
|
19
20
|
else
|
21
|
+
k = options[:symbolize_keys] ? k.to_sym : k.to_s
|
20
22
|
out[k] = Hash === self[k] ? self[k].to_hash : self[k]
|
21
23
|
end
|
22
24
|
end
|
data/lib/hashie/version.rb
CHANGED
data/spec/hashie/mash_spec.rb
CHANGED
@@ -317,37 +317,38 @@ describe Hashie::Mash do
|
|
317
317
|
converted.to_hash["a"].first.is_a?(Hashie::Mash).should be_false
|
318
318
|
converted.to_hash["a"].first.is_a?(Hash).should be_true
|
319
319
|
converted.to_hash["a"].first["c"].first.is_a?(Hashie::Mash).should be_false
|
320
|
+
converted.to_hash({:symbolize_keys => true}).keys[0].should == :a
|
320
321
|
end
|
321
322
|
end
|
322
|
-
|
323
|
+
|
323
324
|
describe "#fetch" do
|
324
325
|
let(:hash) { {:one => 1} }
|
325
326
|
let(:mash) { Hashie::Mash.new(hash) }
|
326
|
-
|
327
|
+
|
327
328
|
context "when key exists" do
|
328
329
|
it "returns the value" do
|
329
330
|
mash.fetch(:one).should eql(1)
|
330
331
|
end
|
331
|
-
|
332
|
+
|
332
333
|
context "when key has other than original but acceptable type" do
|
333
334
|
it "returns the value" do
|
334
335
|
mash.fetch('one').should eql(1)
|
335
336
|
end
|
336
337
|
end
|
337
338
|
end
|
338
|
-
|
339
|
+
|
339
340
|
context "when key does not exist" do
|
340
341
|
it "should raise KeyError" do
|
341
342
|
error = RUBY_VERSION =~ /1.8/ ? IndexError : KeyError
|
342
343
|
expect { mash.fetch(:two) }.to raise_error(error)
|
343
344
|
end
|
344
|
-
|
345
|
+
|
345
346
|
context "with default value given" do
|
346
347
|
it "returns default value" do
|
347
348
|
mash.fetch(:two, 8).should eql(8)
|
348
349
|
end
|
349
350
|
end
|
350
|
-
|
351
|
+
|
351
352
|
context "with block given" do
|
352
353
|
it "returns default value" do
|
353
354
|
mash.fetch(:two) {|key|
|