collapsium 0.8.0 → 0.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac48359cda7fa845f6ee9bf88db8da16b190899d
4
- data.tar.gz: c7c5c3c9c28978e1c85d397ea6a731bdaf911042
3
+ metadata.gz: 99a1088fec0a9bbcf2a9d47fb75e7447076e2c62
4
+ data.tar.gz: c0c3e428c35090a49f249beadff437fa6bda5bd4
5
5
  SHA512:
6
- metadata.gz: eebf8ce4bcbab3920f3809ccb793e33da5b4343ec14c8e2c5b8edb7309f80a06e8b3c6c21dcad144484148c2adf56d19af21fbf9e3987ff3346ae95ec6d95891
7
- data.tar.gz: da064743e896e5fe6505d2fc9dd5213adec4964dc93871b97a74592da0e0569df87590e3d75bde56ae532b1b7c7a1c5c7aeb309039998bd706deea7ff3f1730b
6
+ metadata.gz: c3336fb842483ffce622e2db745345cb2c3647fc17ba66d8b09ac7c082f88e4b538fcd72ced6b5c4614746a8a4c8c37b26fa363d07de3f425f9206b9b9434194
7
+ data.tar.gz: d548be9a8b9a4cf527024ae41e6e8563decebcbd08929137fbb4998bcee40b59c970c2454d18a84474a3de44f5d883d3a8010de5470e049258033fda4e2dbb26
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- collapsium (0.8.0)
4
+ collapsium (0.8.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -71,12 +71,12 @@ module Collapsium
71
71
  return sorted
72
72
  end
73
73
 
74
- READ_METHODS = (
74
+ METHODS = (
75
75
  ::Collapsium::Support::HashMethods::KEYED_READ_METHODS \
76
76
  + ::Collapsium::Support::HashMethods::KEYED_WRITE_METHODS
77
77
  ).freeze
78
78
 
79
- INDIFFERENT_ACCESS_READER = proc do |wrapped_method, *args, &block|
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
- result = nil
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 not result.nil?
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
- READ_METHODS.each do |method|
129
+ METHODS.each do |method|
127
130
  wrap_method(base, method, raise_on_missing: false,
128
- &INDIFFERENT_ACCESS_READER)
131
+ &INDIFFERENT_ACCESS)
129
132
  end
130
133
  end
131
134
  end # class << self
@@ -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
- include PathedAccess
31
- include IndifferentAccess
38
+
39
+ # Lastly, miscellaneous extensions
32
40
  include PrototypeMatch
33
41
 
34
42
  include Support::HashMethods
@@ -8,5 +8,5 @@
8
8
  #
9
9
  module Collapsium
10
10
  # The current release version
11
- VERSION = "0.8.0".freeze
11
+ VERSION = "0.8.1".freeze
12
12
  end
@@ -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 overwriting" do
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
@@ -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.0
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-22 00:00:00.000000000 Z
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler