collapsium 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/collapsium/support/path_components'
3
+
4
+ describe ::Collapsium::Support::PathComponents do
5
+ let(:tester) { Class.new { extend ::Collapsium::Support::PathComponents } }
6
+
7
+ context "#separator" do
8
+ it "defaults to DEFAULT_SEPARATOR" do
9
+ expect(tester.separator).to eql \
10
+ ::Collapsium::Support::PathComponents::DEFAULT_SEPARATOR
11
+ end
12
+
13
+ it "can be set" do
14
+ expect { tester.separator = ':' }.not_to raise_error
15
+ expect(tester.separator).to eql ':'
16
+
17
+ tester.separator = ::Collapsium::Support::PathComponents::DEFAULT_SEPARATOR
18
+ end
19
+ end
20
+
21
+ context "#path_prefix" do
22
+ it "defaults to an empty string" do
23
+ expect(tester.path_prefix).to eql '.' # == DEFAULT_SEPARATOR
24
+ end
25
+
26
+ it "can be set, but normalizes its value" do
27
+ expect { tester.path_prefix = 'foo' }.not_to raise_error
28
+ expect(tester.path_prefix).to eql '.foo' # == DEFAULT_SEPARATOR + 'foo'
29
+
30
+ tester.path_prefix = ''
31
+ end
32
+ end
33
+
34
+ context "#path_components" do
35
+ it "splits a path into components" do
36
+ expect(tester.path_components("foo.bar")).to eql %w(foo bar)
37
+ end
38
+
39
+ it "strips empty components at the beginning" do
40
+ expect(tester.path_components("..foo.bar")).to eql %w(foo bar)
41
+ end
42
+
43
+ it "strips empty components at the end" do
44
+ expect(tester.path_components("foo.bar..")).to eql %w(foo bar)
45
+ end
46
+
47
+ it "strips empty components in the middle" do
48
+ expect(tester.path_components("foo...bar")).to eql %w(foo bar)
49
+ end
50
+ end
51
+
52
+ context "#join_path" do
53
+ it "joins path components" do
54
+ expect(tester.join_path(%w(foo bar))).to eql "foo.bar"
55
+ end
56
+
57
+ it "joins empty components to an empty string" do
58
+ expect(tester.join_path([])).to eql ""
59
+ end
60
+ end
61
+
62
+ context "#normalize_path" do
63
+ it "normalizes a path" do
64
+ expect(tester.normalize_path("foo..bar..baz.")).to eql ".foo.bar.baz"
65
+ end
66
+
67
+ it "normalizes an array path" do
68
+ expect(tester.normalize_path(['foo', '', 'bar'])).to eql ".foo.bar"
69
+ end
70
+ end
71
+
72
+ context "#parent_path" do
73
+ it "returns the parent of a path" do
74
+ expect(tester.parent_path(".foo.bar")).to eql ".foo"
75
+ end
76
+
77
+ it "can deal with children of the root" do
78
+ expect(tester.parent_path(".foo")).to eql "."
79
+ end
80
+
81
+ it "can deal with empty paths" do
82
+ expect(tester.parent_path("")).to eql "."
83
+ end
84
+ end
85
+ end
@@ -20,6 +20,10 @@ class ExtendedHash < Hash
20
20
  extend TestModule
21
21
  end
22
22
 
23
+ class IncludedArray < Array
24
+ include TestModule
25
+ end
26
+
23
27
  class DirectPrependedHash < Hash
24
28
  prepend ::Collapsium::ViralCapabilities
25
29
 
@@ -67,7 +71,7 @@ module ViralityModule
67
71
  extend ::Collapsium::ViralCapabilities
68
72
  include ::Collapsium::Support::Methods
69
73
 
70
- def virality(value)
74
+ def virality(value, *_)
71
75
  # Wrap :delete to become a no-op
72
76
  wrap_method(value, :delete) do
73
77
  next true
@@ -80,7 +84,7 @@ describe ::Collapsium::ViralCapabilities do
80
84
  context PrependedHash do
81
85
  let(:tester) do
82
86
  x = PrependedHash.new
83
- x.merge!(foo: { bar: { baz: true } })
87
+ x.merge!(foo: { bar: [{ baz: true }] })
84
88
  end
85
89
 
86
90
  before do
@@ -89,14 +93,15 @@ describe ::Collapsium::ViralCapabilities do
89
93
 
90
94
  it "replicates itself" do
91
95
  expect(tester[:foo].respond_to?(:find_me)).to be_truthy
92
- expect(tester[:foo][:bar].respond_to?(:find_me)).to be_truthy
96
+ expect(tester[:foo][:bar][0].respond_to?(:find_me)).to be_truthy
97
+ expect(tester[:foo][:bar][0].class).to eql PrependedHash
93
98
  end
94
99
  end
95
100
 
96
101
  context IncludedHash do
97
102
  let(:tester) do
98
103
  x = IncludedHash.new
99
- x.merge!(foo: { bar: { baz: true } })
104
+ x.merge!(foo: { bar: [{ baz: true }] })
100
105
  end
101
106
 
102
107
  before do
@@ -105,14 +110,32 @@ describe ::Collapsium::ViralCapabilities do
105
110
 
106
111
  it "replicates itself" do
107
112
  expect(tester[:foo].respond_to?(:find_me)).to be_truthy
108
- expect(tester[:foo][:bar].respond_to?(:find_me)).to be_truthy
113
+ expect(tester[:foo][:bar][0].respond_to?(:find_me)).to be_truthy
114
+ expect(tester[:foo][:bar][0].class).to eql IncludedHash
115
+ end
116
+ end
117
+
118
+ context IncludedArray do
119
+ let(:tester) do
120
+ x = IncludedArray.new
121
+ x << { foo: { bar: [{ baz: true }, 42] } }
122
+ end
123
+
124
+ before do
125
+ expect(tester.respond_to?(:find_me)).to be_truthy
126
+ end
127
+
128
+ it "replicates itself" do
129
+ expect(tester[0][:foo].respond_to?(:find_me)).to be_truthy
130
+ expect(tester[0][:foo][:bar][0].respond_to?(:find_me)).to be_truthy
131
+ expect(tester[0][:foo][:bar].class).to eql IncludedArray
109
132
  end
110
133
  end
111
134
 
112
135
  context ExtendedHash do
113
136
  let(:tester) do
114
137
  x = ExtendedHash.new
115
- x.merge!(foo: { bar: { baz: true } })
138
+ x.merge!(foo: { bar: [{ baz: true }] })
116
139
  end
117
140
 
118
141
  it "does not receive viral capabilities" do
@@ -123,7 +146,7 @@ describe ::Collapsium::ViralCapabilities do
123
146
  context DirectPrependedHash do
124
147
  let(:tester) do
125
148
  x = DirectPrependedHash.new
126
- x.merge!(foo: { bar: { baz: true } })
149
+ x.merge!(foo: { bar: [{ baz: true }] })
127
150
  end
128
151
 
129
152
  before do
@@ -138,7 +161,7 @@ describe ::Collapsium::ViralCapabilities do
138
161
  context DirectIncludedHash do
139
162
  let(:tester) do
140
163
  x = DirectIncludedHash.new
141
- x.merge!(foo: { bar: { baz: true } })
164
+ x.merge!(foo: { bar: [{ baz: true }] })
142
165
  end
143
166
 
144
167
  before do
@@ -147,14 +170,14 @@ describe ::Collapsium::ViralCapabilities do
147
170
 
148
171
  it "replicates itself" do
149
172
  expect(tester[:foo].respond_to?(:find_me)).to be_truthy
150
- expect(tester[:foo][:bar].respond_to?(:find_me)).to be_truthy
173
+ expect(tester[:foo][:bar][0].respond_to?(:find_me)).to be_truthy
151
174
  end
152
175
  end
153
176
 
154
177
  context DirectExtendedHash do
155
178
  let(:tester) do
156
179
  x = DirectExtendedHash.new
157
- x.merge!(foo: { bar: { baz: true } })
180
+ x.merge!(foo: { bar: [{ baz: true }] })
158
181
  end
159
182
 
160
183
  before do
@@ -163,7 +186,7 @@ describe ::Collapsium::ViralCapabilities do
163
186
 
164
187
  it "replicates itself" do
165
188
  expect(tester[:foo].respond_to?(:find_me)).to be_truthy
166
- expect(tester[:foo][:bar].respond_to?(:find_me)).to be_truthy
189
+ expect(tester[:foo][:bar][0].respond_to?(:find_me)).to be_truthy
167
190
  end
168
191
  end
169
192
 
@@ -186,7 +209,7 @@ describe ::Collapsium::ViralCapabilities do
186
209
  let(:tester) do
187
210
  x = {}
188
211
  x.extend(TestModule)
189
- x.merge!(foo: { bar: { baz: true } })
212
+ x.merge!(foo: { bar: [{ baz: { quux: true } }] })
190
213
  end
191
214
 
192
215
  before do
@@ -195,7 +218,7 @@ describe ::Collapsium::ViralCapabilities do
195
218
 
196
219
  it "replicates itself" do
197
220
  expect(tester[:foo].respond_to?(:find_me)).to be_truthy
198
- expect(tester[:foo][:bar].respond_to?(:find_me)).to be_truthy
221
+ expect(tester[:foo][:bar][0][:baz].respond_to?(:find_me)).to be_truthy
199
222
  end
200
223
  end
201
224
 
@@ -203,7 +226,7 @@ describe ::Collapsium::ViralCapabilities do
203
226
  let(:tester) do
204
227
  x = {}
205
228
  x.extend(ViralityModule)
206
- x.merge!(foo: { bar: { baz: true } })
229
+ x.merge!(foo: { bar: [{ baz: true }] })
207
230
  end
208
231
 
209
232
  before do
@@ -214,7 +237,7 @@ describe ::Collapsium::ViralCapabilities do
214
237
  # Just check that the module went viral; it doesn't check the viral
215
238
  # enhancements work.
216
239
  expect(tester[:foo].respond_to?(:virality)).to be_truthy
217
- expect(tester[:foo][:bar].respond_to?(:virality)).to be_truthy
240
+ expect(tester[:foo][:bar][0].respond_to?(:virality)).to be_truthy
218
241
 
219
242
  # Now also check the viral enhancements. In this case, :delete becomes a
220
243
  # no-op.
@@ -226,19 +249,23 @@ describe ::Collapsium::ViralCapabilities do
226
249
  end
227
250
 
228
251
  context "values already of the same class" do
252
+ # rubocop:disable Performance/RedundantMerge
229
253
  let(:innermost) do
230
254
  innermost = PrependedHash.new
231
255
  innermost.merge!(quux: true)
256
+ innermost
232
257
  end
233
258
 
234
259
  let(:inner) do
235
260
  inner = {}
236
261
  inner.merge!(foo: true, bar: innermost)
262
+ inner
237
263
  end
238
264
 
239
265
  let(:tester) do
240
266
  PrependedHash.new
241
267
  end
268
+ # rubocop:enable Performance/RedundantMerge
242
269
 
243
270
  it "peforms a no-op when adding the right class" do
244
271
  tester[:bar] = inner
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.4.1
4
+ version: 0.5.0
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-08-18 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.42'
33
+ version: '0.44'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.42'
40
+ version: '0.44'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '11.2'
47
+ version: '11.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '11.2'
54
+ version: '11.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -121,8 +121,10 @@ files:
121
121
  - lib/collapsium/recursive_dup.rb
122
122
  - lib/collapsium/recursive_merge.rb
123
123
  - lib/collapsium/recursive_sort.rb
124
+ - lib/collapsium/support/array_methods.rb
124
125
  - lib/collapsium/support/hash_methods.rb
125
126
  - lib/collapsium/support/methods.rb
127
+ - lib/collapsium/support/path_components.rb
126
128
  - lib/collapsium/uber_hash.rb
127
129
  - lib/collapsium/version.rb
128
130
  - lib/collapsium/viral_capabilities.rb
@@ -135,6 +137,7 @@ files:
135
137
  - spec/recursive_sort_spec.rb
136
138
  - spec/spec_helper.rb
137
139
  - spec/support_methods_spec.rb
140
+ - spec/support_path_components.rb
138
141
  - spec/uber_hash_spec.rb
139
142
  - spec/viral_capabilities_spec.rb
140
143
  homepage: https://github.com/jfinkhaeuser/collapsium
@@ -171,5 +174,6 @@ test_files:
171
174
  - spec/recursive_sort_spec.rb
172
175
  - spec/spec_helper.rb
173
176
  - spec/support_methods_spec.rb
177
+ - spec/support_path_components.rb
174
178
  - spec/uber_hash_spec.rb
175
179
  - spec/viral_capabilities_spec.rb