hashr 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hashr (0.0.12)
4
+ hashr (0.0.13)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -10,12 +10,21 @@ class Hash
10
10
  end unless Hash.method_defined?(:except)
11
11
 
12
12
  def deep_symbolize_keys
13
- inject({}) { |result, (key, value)|
14
- value = value.deep_symbolize_keys if value.is_a?(Hash)
15
- result[(key.to_sym rescue key) || key] = value
13
+ symbolizer = lambda do |value|
14
+ case value
15
+ when Hash
16
+ value.deep_symbolize_keys
17
+ when Array
18
+ value.map { |value| symbolizer.call(value) }
19
+ else
20
+ value
21
+ end
22
+ end
23
+ inject({}) do |result, (key, value)|
24
+ result[(key.to_sym rescue key) || key] = symbolizer.call(value)
16
25
  result
17
- }
18
- end unless Hash.method_defined?(:deep_symbolize_keys)
26
+ end
27
+ end
19
28
 
20
29
  # deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
21
30
  def deep_merge(other)
@@ -1,3 +1,3 @@
1
1
  class Hashr < Hash
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class CoreExtTest < Test::Unit::TestCase
4
+ test 'deep_symbolize_keys walks arrays, too' do
5
+ hash = { 'foo' => [{ 'bar' => 'bar', 'baz' => { 'buz' => 'buz' } }] }
6
+ expected = { :foo => [{ :bar => 'bar', :baz => { :buz => 'buz' } }] }
7
+ assert_equal expected, hash.deep_symbolize_keys
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-27 00:00:00.000000000Z
12
+ date: 2011-08-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70271315078720 !ruby/object:Gem::Requirement
16
+ requirement: &70340642451540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70271315078720
24
+ version_requirements: *70340642451540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: test_declarative
27
- requirement: &70271315078080 !ruby/object:Gem::Requirement
27
+ requirement: &70340642450700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.0.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70271315078080
35
+ version_requirements: *70340642450700
36
36
  description: Simple Hash extension to make working with nested hashes (e.g. for configuration)
37
37
  easier and less error-prone.
38
38
  email: svenfuchs@artweb-design.de
@@ -44,6 +44,7 @@ files:
44
44
  - lib/hashr/env_defaults.rb
45
45
  - lib/hashr/version.rb
46
46
  - lib/hashr.rb
47
+ - test/core_ext_test.rb
47
48
  - test/hashr_test.rb
48
49
  - test/test_helper.rb
49
50
  - Gemfile