hash_tools 1.0.0 → 1.1.0
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/.travis.yml +6 -0
- data/README.md +5 -2
- data/hash_tools.gemspec +4 -3
- data/lib/hash_tools.rb +1 -1
- data/lib/hash_tools/indifferent.rb +9 -0
- data/spec/hash_tools/indifferent_spec.rb +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18fecec7d7499d73290542b45404f78aa73e6826
|
4
|
+
data.tar.gz: b5e668e9960f1ce84a595d34edd4b3a579cc716d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4cbf139964133adcfd7a5997b8478bed82dbd0429b0efef9386568e54a47d0b9bf86cfc6832108892911c6d875370b88ba7f1e7a39664937b615ea65c64f557
|
7
|
+
data.tar.gz: 0b82a9e0dc78a402cad1a06d8d6078b04edbf7f3b174d2caf5f3d5daad73a3831e1ddb33e8b7eb9da7270f83ab40c86c31cacfe19560cc36d890eeebd41e9625
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# hash_tools
|
2
2
|
|
3
|
+
[](https://travis-ci.org/WeTransfer/hash_tools)
|
4
|
+
|
3
5
|
Do things to Hashes, without injecting methods into them or extending core classes of the language.
|
4
6
|
And mostly without being too smart. Does not require ActiveSupport.
|
5
7
|
|
6
8
|
Transforming the keys of a hash:
|
7
9
|
|
8
|
-
HashTools
|
10
|
+
HashTools.transform_keys_of({'foo' => 1}, &:upcase) #=> {'FOO' => 1}, works recursively
|
9
11
|
|
10
12
|
Fetching multiple values from a Hash:
|
11
13
|
|
@@ -32,6 +34,7 @@ A simple indifferent access proxy:
|
|
32
34
|
h = {'foo'=>{bar: 2}}
|
33
35
|
w = HashTools.indifferent(h)
|
34
36
|
w[:foo][:bar] #=> 2
|
37
|
+
w.foo.bar #=> 2
|
35
38
|
|
36
39
|
Check the documentation for the separate modules for more.
|
37
40
|
|
@@ -47,6 +50,6 @@ Check the documentation for the separate modules for more.
|
|
47
50
|
|
48
51
|
## Copyright
|
49
52
|
|
50
|
-
Copyright (c) 2015
|
53
|
+
Copyright (c) 2015 WeTransfer. See LICENSE.txt for
|
51
54
|
further details.
|
52
55
|
|
data/hash_tools.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
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.
|
5
|
+
# stub: hash_tools 1.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "hash_tools"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.1.0"
|
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"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-11-02"
|
15
15
|
s.description = "Do useful things to Ruby Hashes"
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".rspec",
|
24
|
+
".travis.yml",
|
24
25
|
".yardopts",
|
25
26
|
"Gemfile",
|
26
27
|
"LICENSE.txt",
|
data/lib/hash_tools.rb
CHANGED
@@ -82,6 +82,15 @@ class HashTools::Indifferent < SimpleDelegator
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
def method_missing(method_name, *args)
|
86
|
+
return self[method_name] if key?(method_name) && args.empty?
|
87
|
+
super
|
88
|
+
end
|
89
|
+
|
90
|
+
def respond_to_missing?(method_name)
|
91
|
+
key?(method_name)
|
92
|
+
end
|
93
|
+
|
85
94
|
alias_method :has_key?, :key?
|
86
95
|
|
87
96
|
private
|
@@ -15,9 +15,21 @@ describe HashTools::Indifferent do
|
|
15
15
|
expect(wrapper.fetch('b')).to eq(2)
|
16
16
|
expect(wrapper.fetch(:b)).to eq(2)
|
17
17
|
|
18
|
+
expect(wrapper.a).to eq(1)
|
19
|
+
expect(wrapper.b).to eq(2)
|
20
|
+
|
18
21
|
expect(wrapper.keys).to eq(h_syms.keys)
|
19
22
|
end
|
20
23
|
|
24
|
+
it 'raises NoMethodError when accessing missing keys via dot notation' do
|
25
|
+
h_syms = {a: 1, 'b' => 2}
|
26
|
+
wrapper = described_class.new(h_syms)
|
27
|
+
|
28
|
+
expect {
|
29
|
+
wrapper.c
|
30
|
+
}.to raise_error(NoMethodError)
|
31
|
+
end
|
32
|
+
|
21
33
|
it 'supports indifferent access to deeply nested hashes' do
|
22
34
|
h_deep = {a: {:b => 1, 'c' => 2}}
|
23
35
|
|
@@ -28,6 +40,9 @@ describe HashTools::Indifferent do
|
|
28
40
|
expect(wrapper[:a][:c]).to eq(2)
|
29
41
|
expect(wrapper['a']['c']).to eq(2)
|
30
42
|
|
43
|
+
expect(wrapper.a.b).to eq(1)
|
44
|
+
expect(wrapper.a.c).to eq(2)
|
45
|
+
|
31
46
|
expect(wrapper.keys).to eq(h_deep.keys)
|
32
47
|
end
|
33
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -68,6 +68,7 @@ extra_rdoc_files:
|
|
68
68
|
files:
|
69
69
|
- ".document"
|
70
70
|
- ".rspec"
|
71
|
+
- ".travis.yml"
|
71
72
|
- ".yardopts"
|
72
73
|
- Gemfile
|
73
74
|
- LICENSE.txt
|