hash_tools 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hash_tools.gemspec +2 -2
- data/lib/hash_tools.rb +1 -1
- data/lib/hash_tools/indifferent.rb +13 -0
- data/spec/hash_tools/indifferent_spec.rb +10 -0
- 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: f54f9fd6710aaef28b13b13637b86bdd9f0ea7da
|
4
|
+
data.tar.gz: db6c828e930c6d65f73ecade6369c0f5f7dc7e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6c201fc0de4f0bc85eb458d9ba76e1c1aa3b0e06b4d4e52703edda33fc48ff75cf1620192cdb8f6c175c43d36983f6878a9d917470cf0c27f5d3f27a052d5f
|
7
|
+
data.tar.gz: 2582099ceb80dd540f8b5bb04b086ef576960eb221a5a251f4830008ed458ea373fbe918c97fb30bef0246eaae86d84027fcaed3f7e7d46d985b6f73bd9023cf
|
data/hash_tools.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: hash_tools 1.1.
|
5
|
+
# stub: hash_tools 1.1.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "hash_tools"
|
9
|
-
s.version = "1.1.
|
9
|
+
s.version = "1.1.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
data/lib/hash_tools.rb
CHANGED
@@ -75,6 +75,9 @@ class HashTools::Indifferent < SimpleDelegator
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
# Maps over keys and values of the Hash. The key class will be preserved (i.e. within
|
79
|
+
# the block the keys will be either Strings or Symbols depending on what is used in the
|
80
|
+
# underlying Hash).
|
78
81
|
def map(&blk)
|
79
82
|
keys.map do |k|
|
80
83
|
tk = __transform_key__(k)
|
@@ -82,6 +85,16 @@ class HashTools::Indifferent < SimpleDelegator
|
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
88
|
+
# There is a quirk whereby the delegate library will not pass `to_json` to the
|
89
|
+
# contained Hash, and the Indifferent would the JSON-serialize as a String.
|
90
|
+
# We have to forward this method explicitly.
|
91
|
+
#
|
92
|
+
# In general, the method will never be called by the user directly but will instead
|
93
|
+
# be excercised by `JSON.dump()` and friends.
|
94
|
+
def to_json(*serializer_state)
|
95
|
+
to_h.to_json(*serializer_state)
|
96
|
+
end
|
97
|
+
|
85
98
|
def method_missing(method_name, *args)
|
86
99
|
return self[method_name] if key?(method_name) && args.empty?
|
87
100
|
super
|
@@ -21,6 +21,16 @@ describe HashTools::Indifferent do
|
|
21
21
|
expect(wrapper.keys).to eq(h_syms.keys)
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'serializes as a JSON object when used as an array member' do
|
25
|
+
require 'json'
|
26
|
+
h = {a: 1}
|
27
|
+
i = described_class.new(h)
|
28
|
+
array = [h, i]
|
29
|
+
dumped = JSON.dump(array)
|
30
|
+
loaded = JSON.load(dumped)
|
31
|
+
expect(loaded[1]).to eq(loaded[0]) # The object representations should be equivalent
|
32
|
+
end
|
33
|
+
|
24
34
|
it 'raises NoMethodError when accessing missing keys via dot notation' do
|
25
35
|
h_syms = {a: 1, 'b' => 2}
|
26
36
|
wrapper = described_class.new(h_syms)
|