collapsium 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/collapsium/indifferent_access.rb +10 -7
- data/lib/collapsium/uber_hash.rb +10 -2
- data/lib/collapsium/version.rb +1 -1
- data/spec/pathed_access_spec.rb +14 -1
- data/spec/uber_hash_spec.rb +29 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99a1088fec0a9bbcf2a9d47fb75e7447076e2c62
|
4
|
+
data.tar.gz: c0c3e428c35090a49f249beadff437fa6bda5bd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3336fb842483ffce622e2db745345cb2c3647fc17ba66d8b09ac7c082f88e4b538fcd72ced6b5c4614746a8a4c8c37b26fa363d07de3f425f9206b9b9434194
|
7
|
+
data.tar.gz: d548be9a8b9a4cf527024ae41e6e8563decebcbd08929137fbb4998bcee40b59c970c2454d18a84474a3de44f5d883d3a8010de5470e049258033fda4e2dbb26
|
data/Gemfile.lock
CHANGED
@@ -71,12 +71,12 @@ module Collapsium
|
|
71
71
|
return sorted
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
METHODS = (
|
75
75
|
::Collapsium::Support::HashMethods::KEYED_READ_METHODS \
|
76
76
|
+ ::Collapsium::Support::HashMethods::KEYED_WRITE_METHODS
|
77
77
|
).freeze
|
78
78
|
|
79
|
-
|
79
|
+
INDIFFERENT_ACCESS = proc do |wrapped_method, *args, &block|
|
80
80
|
# Bail out early if the receiver is not a Hash. Do the same if we have
|
81
81
|
# no key.
|
82
82
|
receiver = wrapped_method.receiver
|
@@ -89,8 +89,11 @@ module Collapsium
|
|
89
89
|
key = args.shift
|
90
90
|
tries = IndifferentAccess.key_permutations(key)
|
91
91
|
|
92
|
-
# With the variations to try assembled, go through them one by one
|
93
|
-
|
92
|
+
# With the variations to try assembled, go through them one by one. We
|
93
|
+
# define an inner class here for undefined results because 'nil' can be
|
94
|
+
# a legitimate result from the wrapped method.
|
95
|
+
class Undefined; end
|
96
|
+
result = Undefined
|
94
97
|
tries.each do |try|
|
95
98
|
if receiver.keys.include?(try)
|
96
99
|
result = wrapped_method.call(try, *args, &block)
|
@@ -100,7 +103,7 @@ module Collapsium
|
|
100
103
|
|
101
104
|
# If any of the above yielded a result, great, return that. Otherwise
|
102
105
|
# yield to the default implementation (i.e. wrapped_method).
|
103
|
-
if
|
106
|
+
if result != Undefined
|
104
107
|
next result
|
105
108
|
end
|
106
109
|
next wrapped_method.call(key, *args, &block)
|
@@ -123,9 +126,9 @@ module Collapsium
|
|
123
126
|
base.extend(ViralCapabilities)
|
124
127
|
|
125
128
|
# Wrap all accessor functions to deal with paths
|
126
|
-
|
129
|
+
METHODS.each do |method|
|
127
130
|
wrap_method(base, method, raise_on_missing: false,
|
128
|
-
&
|
131
|
+
&INDIFFERENT_ACCESS)
|
129
132
|
end
|
130
133
|
end
|
131
134
|
end # class << self
|
data/lib/collapsium/uber_hash.rb
CHANGED
@@ -22,13 +22,21 @@ module Collapsium
|
|
22
22
|
|
23
23
|
# A Hash that includes all the different Hash extensions in collapsium
|
24
24
|
class UberHash < Hash
|
25
|
+
# ViralCapabilities first, just to ensure everything will get inherited.
|
25
26
|
include ViralCapabilities
|
27
|
+
|
28
|
+
# Access methods next.
|
29
|
+
include IndifferentAccess
|
30
|
+
include PathedAccess
|
31
|
+
|
32
|
+
# Recursive functionality should be able to use access methods, so they
|
33
|
+
# come next.
|
26
34
|
include RecursiveMerge
|
27
35
|
include RecursiveDup
|
28
36
|
include RecursiveSort
|
29
37
|
include RecursiveFetch
|
30
|
-
|
31
|
-
|
38
|
+
|
39
|
+
# Lastly, miscellaneous extensions
|
32
40
|
include PrototypeMatch
|
33
41
|
|
34
42
|
include Support::HashMethods
|
data/lib/collapsium/version.rb
CHANGED
data/spec/pathed_access_spec.rb
CHANGED
@@ -273,7 +273,7 @@ describe ::Collapsium::PathedAccess do
|
|
273
273
|
expect(res['bar']).to eql 42
|
274
274
|
end
|
275
275
|
|
276
|
-
it "can write without
|
276
|
+
it "can write without duplication" do
|
277
277
|
tester = {
|
278
278
|
foo: {
|
279
279
|
bar: 42,
|
@@ -284,11 +284,24 @@ describe ::Collapsium::PathedAccess do
|
|
284
284
|
tester.extend(::Collapsium::IndifferentAccess)
|
285
285
|
|
286
286
|
expect(tester['foo.bar']).to eql 42
|
287
|
+
expect(tester[:foo][:bar]).to eql 42
|
287
288
|
expect(tester['foo.baz']).to eql 'quux'
|
289
|
+
expect(tester[:foo][:baz]).to eql 'quux'
|
290
|
+
expect(tester['foo'].length).to eql 2
|
288
291
|
|
289
292
|
tester['foo.bar'] = 123
|
290
293
|
expect(tester['foo.bar']).to eql 123
|
294
|
+
expect(tester[:foo][:bar]).to eql 123
|
291
295
|
expect(tester['foo.baz']).to eql 'quux'
|
296
|
+
expect(tester[:foo][:baz]).to eql 'quux'
|
297
|
+
expect(tester['foo'].length).to eql 2
|
298
|
+
|
299
|
+
tester['foo.bar'] = nil
|
300
|
+
expect(tester['foo.bar']).to be_nil
|
301
|
+
expect(tester[:foo][:bar]).to be_nil
|
302
|
+
expect(tester['foo.baz']).to eql 'quux'
|
303
|
+
expect(tester[:foo][:baz]).to eql 'quux'
|
304
|
+
expect(tester['foo'].length).to eql 2
|
292
305
|
end
|
293
306
|
|
294
307
|
it "doesn't break #path_prefix" do
|
data/spec/uber_hash_spec.rb
CHANGED
@@ -37,6 +37,35 @@ describe Collapsium::UberHash do
|
|
37
37
|
expect(x[:foo]).to eql 42
|
38
38
|
end
|
39
39
|
|
40
|
+
it "mixes pathed and indifferent access well" do
|
41
|
+
x = ::Collapsium::UberHash.new(
|
42
|
+
foo: {
|
43
|
+
bar: 42,
|
44
|
+
baz: 'quux',
|
45
|
+
}
|
46
|
+
)
|
47
|
+
|
48
|
+
expect(x['foo.bar']).to eql 42
|
49
|
+
expect(x[:foo][:bar]).to eql 42
|
50
|
+
expect(x['foo.baz']).to eql 'quux'
|
51
|
+
expect(x[:foo][:baz]).to eql 'quux'
|
52
|
+
expect(x['foo'].length).to eql 2
|
53
|
+
|
54
|
+
x['foo.bar'] = 123
|
55
|
+
expect(x['foo.bar']).to eql 123
|
56
|
+
expect(x[:foo][:bar]).to eql 123
|
57
|
+
expect(x['foo.baz']).to eql 'quux'
|
58
|
+
expect(x[:foo][:baz]).to eql 'quux'
|
59
|
+
expect(x['foo'].length).to eql 2
|
60
|
+
|
61
|
+
x['foo.bar'] = nil
|
62
|
+
expect(x['foo.bar']).to be_nil
|
63
|
+
expect(x[:foo][:bar]).to be_nil
|
64
|
+
expect(x['foo.baz']).to eql 'quux'
|
65
|
+
expect(x[:foo][:baz]).to eql 'quux'
|
66
|
+
expect(x['foo'].length).to eql 2
|
67
|
+
end
|
68
|
+
|
40
69
|
it "can be initialized without arguments" do
|
41
70
|
x = ::Collapsium::UberHash.new
|
42
71
|
expect(x.empty?).to be_truthy
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collapsium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Finkhaeuser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|