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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac16efc13aefffe539cf133c3bb1031fc70063ac
4
- data.tar.gz: b01ab2ee885aa1e26201ef34c0973681fa726b66
3
+ metadata.gz: f54f9fd6710aaef28b13b13637b86bdd9f0ea7da
4
+ data.tar.gz: db6c828e930c6d65f73ecade6369c0f5f7dc7e6a
5
5
  SHA512:
6
- metadata.gz: 83305ccfaea1f7aed833bee8307ca2729bf5ff63385390f161b2690b4e75fa1ab8a677295a9f45ff24d31a6842d6d5713fffccd456e3025b8c3c9e2f72d9a48a
7
- data.tar.gz: 2a94cd920677ddd3298bfd13ddbdd7a1d89596e5345abba4c0e574268a1b7e9a2e3ac87654fa73435faaa9c6bd1ffccb045eb4f0f50375e6b2b0dcef81a7d521
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.1 ruby lib
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.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
@@ -1,5 +1,5 @@
1
1
  module HashTools
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
 
4
4
  require_relative 'hash_tools/indifferent'
5
5
 
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov