compo 0.1.3 → 0.1.4
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/CHANGELOG +7 -0
- data/lib/compo/array_branch.rb +1 -0
- data/lib/compo/hash_branch.rb +1 -0
- data/lib/compo/leaf.rb +1 -0
- data/lib/compo/url_referenceable.rb +49 -0
- data/lib/compo/version.rb +1 -1
- data/lib/compo.rb +1 -0
- data/spec/leaf_spec.rb +16 -0
- data/spec/url_referenceable_spec.rb +75 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c288d0dcd9919802b30e9a7474bbed1ec62ae69
|
4
|
+
data.tar.gz: 63ae3aee08834eec7facefebbccc5e4ba8c8983b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38177f5e0602736715d5e682593dec1eaa28ea64e4f95ea2ed1ae62b82f9d2e98d298643c4b2f9270f2a20286ef6a2c1fd4b3df98e40fbd4ca9ff611b20970d2
|
7
|
+
data.tar.gz: 8c9b77ab21a06ba68029074426bd1c391bd02d147623823627fd4cc848118ac73da8d60204f3e119e6b1e1720ede82cdd1c7b4fa540ee17c29b68d524876c2ff
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.1.4 (2013-12-28)
|
2
|
+
- Implement UrlReferenceable. This adds two new functions, #url and
|
3
|
+
#parent_url, which retrieve a slash/delimited/string/of/IDs starting from
|
4
|
+
the first child in the parent chain from the caller and its parent
|
5
|
+
respectively.
|
6
|
+
- Include UrlReferenceable in ArrayBranch, HashBranch and Leaf.
|
7
|
+
|
1
8
|
0.1.3 (2013-12-28)
|
2
9
|
- Implement ArrayBranch and HashBranch. These bundle ArrayComposite and
|
3
10
|
HashComposite up with the Movable and ParentTracker mixins, for
|
data/lib/compo/array_branch.rb
CHANGED
data/lib/compo/hash_branch.rb
CHANGED
data/lib/compo/leaf.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Compo
|
2
|
+
# Adds ID-based 'URL's to Compo classes
|
3
|
+
#
|
4
|
+
# For the purposes of this module, a URL is a string of slash-delimited IDs
|
5
|
+
# representing the location of a Composite in the tree structure formed by
|
6
|
+
# its ancestors. Depending on the types of IDs used in the structure, the
|
7
|
+
# URLs may not actually be literal Uniform Resource Locators.
|
8
|
+
#
|
9
|
+
# This module expects its includer to define #parent and #id. These are
|
10
|
+
# defined, for example, by the Compo::ParentTracker mixin.
|
11
|
+
module UrlReferenceable
|
12
|
+
# Returns the URL of this object
|
13
|
+
#
|
14
|
+
# The #url of a Composite is defined inductively as '' for composites that
|
15
|
+
# have no parent, and the joining of the parent URL and the current ID
|
16
|
+
# otherwise.
|
17
|
+
#
|
18
|
+
# The result of #url can be used to give a URL hierarchy to Composites.
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
# @example Gets the URL of an object with no parent.
|
22
|
+
# orphan.url
|
23
|
+
# #=> ''
|
24
|
+
# @example Gets the URL of an object with a parent.
|
25
|
+
# leaf.url
|
26
|
+
# #=> 'grandparent_id/parent_id/id'
|
27
|
+
#
|
28
|
+
# @return [String] The URL of this object.
|
29
|
+
def url
|
30
|
+
parent.nil? ? '' : [parent_url, id].join('/')
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the URL of this object's parent
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
# @example Gets the parent URL of an object with no parent.
|
37
|
+
# orphan.parent_url
|
38
|
+
# #=> nil
|
39
|
+
# @example Gets the URL of an object with a parent.
|
40
|
+
# leaf.parent_url
|
41
|
+
# #=> 'grandparent_id/parent_id'
|
42
|
+
#
|
43
|
+
# @return [String] The URL of this object's parent, or nil if there is no
|
44
|
+
# parent.
|
45
|
+
def parent_url
|
46
|
+
parent.nil? ? nil : parent.url
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/compo/version.rb
CHANGED
data/lib/compo.rb
CHANGED
data/spec/leaf_spec.rb
CHANGED
@@ -11,4 +11,20 @@ describe Compo::Leaf do
|
|
11
11
|
expect(subject.id).to be_nil
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
describe '#url' do
|
16
|
+
context 'when the Leaf has no parent' do
|
17
|
+
it 'returns the empty string' do
|
18
|
+
expect(subject.url).to eq('')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'when the Leaf is the child of a root' do
|
22
|
+
let(:parent) { Compo::HashBranch.new }
|
23
|
+
before(:each) { subject.move_to(parent, :id) }
|
24
|
+
|
25
|
+
it 'returns /ID, where ID is the ID of the Leaf' do
|
26
|
+
expect(subject.url).to eq('/id')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
14
30
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'compo'
|
3
|
+
|
4
|
+
# Mock implementation of UrlReferenceable.
|
5
|
+
class MockUrlReferenceable
|
6
|
+
include Compo::UrlReferenceable
|
7
|
+
end
|
8
|
+
|
9
|
+
describe MockUrlReferenceable do
|
10
|
+
before(:each) { allow(subject).to receive(:parent).and_return(parent) }
|
11
|
+
|
12
|
+
describe '#url' do
|
13
|
+
context 'when the UrlReferenceable has no parent' do
|
14
|
+
let(:parent) { nil }
|
15
|
+
|
16
|
+
it 'returns the empty string' do
|
17
|
+
expect(subject.url).to eq('')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the UrlReferenceable has a parent' do
|
22
|
+
let(:parent) { double(:parent) }
|
23
|
+
before(:each) do
|
24
|
+
allow(subject).to receive(:id).and_return('id')
|
25
|
+
allow(subject).to receive(:parent_url).and_return('dog/goes')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'calls #id' do
|
29
|
+
expect(subject).to receive(:id)
|
30
|
+
subject.url
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the joining of the parent URL and ID with a slash' do
|
34
|
+
expect(subject.url).to eq('dog/goes/id')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#parent_url' do
|
40
|
+
context 'when the UrlReferenceable has no parent' do
|
41
|
+
let(:parent) { nil }
|
42
|
+
|
43
|
+
specify { expect(subject.parent_url).to be_nil }
|
44
|
+
|
45
|
+
it 'calls #parent' do
|
46
|
+
expect(subject).to receive(:parent)
|
47
|
+
subject.parent_url
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when the UrlReferenceable has a parent' do
|
52
|
+
let(:parent) { double(:parent) }
|
53
|
+
let(:url) { double(:url) }
|
54
|
+
|
55
|
+
before(:each) do
|
56
|
+
allow(parent).to receive(:url).and_return(url)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'calls #parent' do
|
60
|
+
expect(subject).to receive(:parent).with(no_args)
|
61
|
+
subject.parent_url
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'calls #url on the parent' do
|
65
|
+
expect(parent).to receive(:url).once.with(no_args)
|
66
|
+
subject.parent_url
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the result of #url on the parent' do
|
70
|
+
expect(subject.parent_url).to eq(url)
|
71
|
+
subject.parent_url
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Windsor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backports
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/compo/movable.rb
|
150
150
|
- lib/compo/null_composite.rb
|
151
151
|
- lib/compo/parent_tracker.rb
|
152
|
+
- lib/compo/url_referenceable.rb
|
152
153
|
- lib/compo/version.rb
|
153
154
|
- spec/array_branch_spec.rb
|
154
155
|
- spec/array_composite_spec.rb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- spec/null_composite_spec.rb
|
161
162
|
- spec/parent_tracker_spec.rb
|
162
163
|
- spec/spec_helper.rb
|
164
|
+
- spec/url_referenceable_spec.rb
|
163
165
|
homepage: http://github.com/CaptainHayashi/compo
|
164
166
|
licenses:
|
165
167
|
- MIT
|
@@ -195,4 +197,5 @@ test_files:
|
|
195
197
|
- spec/null_composite_spec.rb
|
196
198
|
- spec/parent_tracker_spec.rb
|
197
199
|
- spec/spec_helper.rb
|
200
|
+
- spec/url_referenceable_spec.rb
|
198
201
|
has_rdoc:
|