hashie 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40d378ad0e9cfb288cc60a0d37420f111abf21ce
4
- data.tar.gz: 0e17c881efb146582099c135fe3e20f6f7aaf392
3
+ metadata.gz: 1308b1b5e87e1b28328361a0b2f2d084839e7864
4
+ data.tar.gz: 2db28fef4c8dc89369658de62b59e046e2076ddb
5
5
  SHA512:
6
- metadata.gz: fdb195cc354097e4dc957e4c5c7e0fa15812f9814b086caa1c7b7849b537d7332e5aeaac5181a6583038557bcd16606bd2f8bd51790cd6eb59eb7a6f78755b3a
7
- data.tar.gz: e41685fe63814432b58155a433f9dbf6134af70b087166e9a8984503cfe6936d7c5e76f3f32a80bedf0e3dc99af335a57ce5e24c017db57382c081f7942a2cdf
6
+ metadata.gz: 7fa20289e9e8a0c57737ed4b79f3c7ea95dd907b8ce5912e75448b1dfe99b4df8b0197bc3719d0ba9db4f995d9d6492cd1a2d0bd0cd1dba748c14d209d4823db
7
+ data.tar.gz: 838e995acf432ebf669768a68d62797c601823ea521a93b448a584ecf9257323376c1632b5c45e324e2ced4a06265e27417fae15d189ecb8f0e8692a7ba9ad3b
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Hashie
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -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|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh