compo 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/lib/compo/composite.rb +17 -0
- data/lib/compo/version.rb +1 -1
- data/spec/composite_spec.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27f469c00cf86d294398a92e891752c829380282
|
4
|
+
data.tar.gz: f3e4f7776ea089dcd80d77a0827f4c77cca6c728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0f0d6d791a42006eeb243311980e21c04338b68ccb4157c54303db2f77b6d08d962a6bdc709385188b52be2fed5b20125c003515294d5e9f1d06fd06f6bca67
|
7
|
+
data.tar.gz: 35962706d2103ccad4c75fa5c4ed6131daa0bc2a9eef3361a056b7edaa692620e6975bb03999744d539fbff272c72ac5a87307ab0e24f9509e4fc7bb4296d5e5
|
data/CHANGELOG
CHANGED
data/lib/compo/composite.rb
CHANGED
@@ -69,6 +69,23 @@ module Compo
|
|
69
69
|
remove_id!(id).tap(&method(:remove_parent_of))
|
70
70
|
end
|
71
71
|
|
72
|
+
# Gets the child in this Composite with the given ID
|
73
|
+
#
|
74
|
+
# @api public
|
75
|
+
# @example Gets the child with ID :in, if children is {in: 3}.
|
76
|
+
# composite.get_child(:in)
|
77
|
+
# #=> 3
|
78
|
+
# @example Fails to get the child with ID :out, if children is {in: 3}.
|
79
|
+
# composite.get_child(:out)
|
80
|
+
# #=> nil
|
81
|
+
#
|
82
|
+
# @param id [Object] The ID of the child to get from this Composite.
|
83
|
+
#
|
84
|
+
# @return [Object] The child if successful; nil otherwise.
|
85
|
+
def get_child(id)
|
86
|
+
children[id]
|
87
|
+
end
|
88
|
+
|
72
89
|
def_delegator :children, :each
|
73
90
|
|
74
91
|
protected
|
data/lib/compo/version.rb
CHANGED
data/spec/composite_spec.rb
CHANGED
@@ -246,4 +246,24 @@ describe MockComposite do
|
|
246
246
|
subject.each
|
247
247
|
end
|
248
248
|
end
|
249
|
+
|
250
|
+
describe '#get_child' do
|
251
|
+
before(:each) { allow(subject).to receive(:children).and_return(children) }
|
252
|
+
let(:children) { { in_children: child } }
|
253
|
+
|
254
|
+
it 'calls #children' do
|
255
|
+
expect(subject).to receive(:children).once
|
256
|
+
subject.get_child(:in_children)
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when the argument is in #children' do
|
260
|
+
it 'returns the child' do
|
261
|
+
expect(subject.get_child(:in_children)).to eq(child)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'when the argument is in #children' do
|
266
|
+
specify { expect(subject.get_child(:not_in_children)).to be_nil }
|
267
|
+
end
|
268
|
+
end
|
249
269
|
end
|