compo 0.4.0 → 0.5.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/.rspec +0 -1
- data/.travis.yml +3 -0
- data/CHANGELOG +11 -0
- data/README.md +3 -0
- data/compo.gemspec +3 -4
- data/lib/compo/composites/composite.rb +16 -0
- data/lib/compo/composites/parentless.rb +14 -15
- data/lib/compo/finders/root.rb +77 -0
- data/lib/compo/finders.rb +1 -0
- data/lib/compo/mixins/parent_tracker.rb +15 -0
- data/lib/compo/mixins/url_referenceable.rb +8 -23
- data/lib/compo/version.rb +1 -1
- data/spec/array_branch_spec.rb +1 -1
- data/spec/array_composite_shared_examples.rb +108 -103
- data/spec/array_composite_spec.rb +1 -1
- data/spec/branch_shared_examples.rb +9 -6
- data/spec/branch_spec.rb +1 -1
- data/spec/composite_shared_examples.rb +64 -47
- data/spec/composite_spec.rb +1 -1
- data/spec/constant_branch_spec.rb +1 -1
- data/spec/hash_branch_spec.rb +1 -1
- data/spec/hash_composite_shared_examples.rb +28 -31
- data/spec/hash_composite_spec.rb +1 -1
- data/spec/leaf_branch_spec.rb +1 -1
- data/spec/leaf_composite_shared_examples.rb +14 -28
- data/spec/leaf_composite_spec.rb +1 -1
- data/spec/movable_shared_examples.rb +4 -4
- data/spec/movable_spec.rb +1 -1
- data/spec/parent_tracker_spec.rb +1 -1
- data/spec/parentless_spec.rb +21 -11
- data/spec/root_finder_spec.rb +66 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/url_finder_shared_examples.rb +1 -1
- data/spec/url_finder_spec.rb +1 -1
- data/spec/url_referenceable_shared_examples.rb +16 -14
- data/spec/url_referenceable_spec.rb +1 -1
- metadata +14 -23
data/spec/parentless_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'compo'
|
3
3
|
|
4
|
-
describe Compo::Composites::Parentless do
|
4
|
+
RSpec.describe Compo::Composites::Parentless do
|
5
5
|
let(:child) { double(:child) }
|
6
6
|
|
7
7
|
describe '#add' do
|
@@ -12,17 +12,20 @@ describe Compo::Composites::Parentless do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'calls #update_parent on the child with a Parentless' do
|
15
|
-
expect(child).to receive(:update_parent).once do |parent, _|
|
16
|
-
expect(parent).to be_a(Compo::Composites::Parentless)
|
17
|
-
end
|
18
15
|
subject.add(:id, child)
|
16
|
+
|
17
|
+
expect(child).to have_received(:update_parent).once.with(
|
18
|
+
a_kind_of(Compo::Composites::Parentless),
|
19
|
+
anything
|
20
|
+
)
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'calls #update_parent on the child with a nil-returning ID proc' do
|
22
|
-
expect(child).to receive(:update_parent).once do |_, idp|
|
23
|
-
expect(idp.call).to be_nil
|
24
|
-
end
|
25
24
|
subject.add(:id, child)
|
25
|
+
expect(child).to have_received(:update_parent).once.with(
|
26
|
+
anything,
|
27
|
+
an_object_satisfying { |idp| idp.call.nil? }
|
28
|
+
)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -40,13 +43,20 @@ describe Compo::Composites::Parentless do
|
|
40
43
|
specify { expect(subject.url).to eq('') }
|
41
44
|
end
|
42
45
|
|
43
|
-
describe '#child_url' do
|
44
|
-
specify { expect(subject.child_url(:id)).to eq('') }
|
45
|
-
end
|
46
|
-
|
47
46
|
describe '#parent' do
|
48
47
|
it 'returns the exact same Parentless object' do
|
49
48
|
expect(subject.parent).to be(subject)
|
50
49
|
end
|
51
50
|
end
|
51
|
+
|
52
|
+
describe '#on_node' do
|
53
|
+
it 'ignores the block given' do
|
54
|
+
expect { |block| subject.on_node(&block) }.to_not yield_control
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns nil' do
|
58
|
+
expect(subject.on_node { |subject| subject }).to be_nil
|
59
|
+
expect(subject.on_node { 3 }).to be_nil
|
60
|
+
end
|
61
|
+
end
|
52
62
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'compo'
|
3
|
+
|
4
|
+
RSpec.describe Compo::Finders::Root do
|
5
|
+
subject { Compo::Finders::Root }
|
6
|
+
|
7
|
+
it { should < Enumerable }
|
8
|
+
|
9
|
+
describe '.find' do
|
10
|
+
context 'when given a root' do
|
11
|
+
it 'returns the root' do
|
12
|
+
l = Compo::Branches::Leaf.new
|
13
|
+
|
14
|
+
expect { |b| subject.find(l, &b) }.to yield_with_args(l)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when given a leaf' do
|
19
|
+
it 'returns its root' do
|
20
|
+
a = Compo::Branches::Hash.new
|
21
|
+
b = Compo::Branches::Hash.new
|
22
|
+
l = Compo::Branches::Leaf.new
|
23
|
+
|
24
|
+
l.move_to(b, :l)
|
25
|
+
b.move_to(a, :b)
|
26
|
+
|
27
|
+
expect { |block| subject.find(l, &block) }.to yield_with_args(a)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.each' do
|
33
|
+
subject { Compo::Finders::Root.new(leaf) }
|
34
|
+
|
35
|
+
context 'when given a root' do
|
36
|
+
let(:leaf) { Compo::Branches::Leaf.new }
|
37
|
+
|
38
|
+
it 'returns the root' do
|
39
|
+
expect { |block| subject.each(&block) }.to yield_with_args(leaf)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when given a leaf' do
|
44
|
+
let(:root) { Compo::Branches::Hash.new }
|
45
|
+
let(:a) { Compo::Branches::Hash.new }
|
46
|
+
let(:b) { Compo::Branches::Hash.new }
|
47
|
+
let(:c) { Compo::Branches::Hash.new }
|
48
|
+
let(:leaf) do
|
49
|
+
l = Compo::Branches::Leaf.new
|
50
|
+
|
51
|
+
l.move_to(c, :l)
|
52
|
+
c.move_to(b, :c)
|
53
|
+
b.move_to(a, :b)
|
54
|
+
a.move_to(root, :a)
|
55
|
+
|
56
|
+
l
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns each item in the path' do
|
60
|
+
expect { |b| subject.each(&b) }.to yield_successive_args(
|
61
|
+
leaf, c, b, a, root
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/url_finder_spec.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
shared_examples 'a URL referenceable object' do
|
1
|
+
RSpec.shared_examples 'a URL referenceable object' do
|
2
2
|
let(:parent) { nil }
|
3
|
-
let(:id) {
|
3
|
+
let(:id) { :id }
|
4
|
+
let(:parent_id) { :parent_id }
|
4
5
|
|
5
6
|
before(:each) do
|
6
|
-
allow(subject).to
|
7
|
-
|
7
|
+
allow(subject).to receive_messages(
|
8
|
+
id: id,
|
9
|
+
parent: parent,
|
10
|
+
root?: false
|
11
|
+
)
|
8
12
|
end
|
9
13
|
|
10
14
|
describe '#url' do
|
@@ -15,26 +19,24 @@ shared_examples 'a URL referenceable object' do
|
|
15
19
|
context 'when the UrlReferenceable has a parent' do
|
16
20
|
let(:parent) { double(:parent) }
|
17
21
|
before(:each) do
|
18
|
-
allow(parent).to
|
22
|
+
allow(parent).to receive_messages(
|
23
|
+
parent: Compo::Composites::Parentless.new,
|
24
|
+
root?: true
|
25
|
+
)
|
19
26
|
end
|
20
27
|
|
21
28
|
it 'calls #id' do
|
22
|
-
expect(subject).to receive(:id)
|
23
29
|
subject.url
|
30
|
+
expect(subject).to have_received(:id)
|
24
31
|
end
|
25
32
|
|
26
33
|
it 'calls #parent' do
|
27
|
-
expect(subject).to receive(:parent)
|
28
34
|
subject.url
|
35
|
+
expect(subject).to have_received(:parent)
|
29
36
|
end
|
30
37
|
|
31
|
-
it '
|
32
|
-
expect(
|
33
|
-
subject.url
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the result of calling #child_url' do
|
37
|
-
expect(subject.url).to eq(:child_url)
|
38
|
+
it 'returns /id' do
|
39
|
+
expect(subject.url).to eq('/id')
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Windsor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backports
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: fuubar
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +56,16 @@ dependencies:
|
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '3'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '3'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: simplecov
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,9 +108,10 @@ dependencies:
|
|
122
108
|
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
|
-
description:
|
126
|
-
|
127
|
-
|
111
|
+
description: |2
|
112
|
+
Compo provides mixins and classes that assist in implementing a variant of
|
113
|
+
the Composite design pattern, in which each child has an ID that uniquely
|
114
|
+
identifies it inside the parent's child set.
|
128
115
|
email:
|
129
116
|
- matt.windsor@ury.org.uk
|
130
117
|
executables: []
|
@@ -133,6 +120,7 @@ extra_rdoc_files: []
|
|
133
120
|
files:
|
134
121
|
- ".gitignore"
|
135
122
|
- ".rspec"
|
123
|
+
- ".travis.yml"
|
136
124
|
- CHANGELOG
|
137
125
|
- Gemfile
|
138
126
|
- LICENSE.txt
|
@@ -153,6 +141,7 @@ files:
|
|
153
141
|
- lib/compo/composites/leaf.rb
|
154
142
|
- lib/compo/composites/parentless.rb
|
155
143
|
- lib/compo/finders.rb
|
144
|
+
- lib/compo/finders/root.rb
|
156
145
|
- lib/compo/finders/url.rb
|
157
146
|
- lib/compo/mixins.rb
|
158
147
|
- lib/compo/mixins/movable.rb
|
@@ -177,6 +166,7 @@ files:
|
|
177
166
|
- spec/movable_spec.rb
|
178
167
|
- spec/parent_tracker_spec.rb
|
179
168
|
- spec/parentless_spec.rb
|
169
|
+
- spec/root_finder_spec.rb
|
180
170
|
- spec/spec_helper.rb
|
181
171
|
- spec/url_finder_shared_examples.rb
|
182
172
|
- spec/url_finder_spec.rb
|
@@ -225,6 +215,7 @@ test_files:
|
|
225
215
|
- spec/movable_spec.rb
|
226
216
|
- spec/parent_tracker_spec.rb
|
227
217
|
- spec/parentless_spec.rb
|
218
|
+
- spec/root_finder_spec.rb
|
228
219
|
- spec/spec_helper.rb
|
229
220
|
- spec/url_finder_shared_examples.rb
|
230
221
|
- spec/url_finder_spec.rb
|