compo 0.1.2 → 0.1.3
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 +5 -0
- data/README.md +21 -1
- data/lib/compo/array_branch.rb +27 -0
- data/lib/compo/hash_branch.rb +28 -0
- data/lib/compo/leaf.rb +7 -3
- data/lib/compo/parent_tracker.rb +1 -1
- data/lib/compo/version.rb +1 -1
- data/lib/compo.rb +14 -5
- data/spec/array_branch_spec.rb +14 -0
- data/spec/hash_branch_spec.rb +14 -0
- metadata +29 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da63ba2221a1640af2ce8c4d72710edf04653e07
|
4
|
+
data.tar.gz: 3459f6450e9b5cf6059afe212a14817c0d8bb6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4366f7d7e68bd32d1654efb4f64ce03f7df671e92e9201da820cbc5a169692fa855c9505e67ade09c10ad7af563c74bcd9d45fca061ee7b5a24a6f96c2b24a28
|
7
|
+
data.tar.gz: f09be088d6aba7563fe1d3a7a7c2a56d3c750d13ade1b5d95a1cbee479af09ceccc17e6c063bb021c7d6b58516ba470fec3700ab517af213c5bc7a94a6ca5bdb
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,27 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
|
29
|
+
Compo consists of several classes and mixins that implement various parts of the composite pattern. In increasing order of general usefulness, they are:
|
30
|
+
|
31
|
+
### Base mixins
|
32
|
+
|
33
|
+
- **Composite**, which specifies the #add/#remove/#remove_id/#get_child API on top of an implementation;
|
34
|
+
- **Movable**, which creates a #move_to method that simplifies the act of moving a child between Composites;
|
35
|
+
- **ParentTracker**, which implements keeping track of a child's parent and the child end of #add/#remove;
|
36
|
+
|
37
|
+
### Composite implementation classes
|
38
|
+
|
39
|
+
These implement the methods needed for **Composite** to work, but don't implement moving, parent tracking, or anything else.
|
40
|
+
|
41
|
+
- **ArrayComposite**, which is a class that implements **Composite** using an Array, with IDs being the array indices;
|
42
|
+
- **HashComposite**, which is a class that implements **Composite** using a Hash, with IDs being the hash keys;
|
43
|
+
- **NullComposite**, which allows no children but implements **Composite** in a way such that all operations fail;
|
44
|
+
|
45
|
+
### Simple leaf and node classes
|
46
|
+
|
47
|
+
These include **Composite**, **Movable** and **ParentTracker**, and thus can be moved around, added to and removed from composites, and track their current parents and IDs.
|
48
|
+
|
49
|
+
- **Leaf**, which is based on NullComposite and is intended for objects that don't have children but can be placed in other Composites.
|
30
50
|
|
31
51
|
## Contributing
|
32
52
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Compo
|
2
|
+
# A simple implementation of a branch, whose children are stored in an Array
|
3
|
+
#
|
4
|
+
# An ArrayBranch is a composite object that may be moved into other composite
|
5
|
+
# objects. It stores its children as an Array, and the ID of each child is
|
6
|
+
# its current index in the array. Inserting and removing items into the
|
7
|
+
# ArrayBranch may change the IDs of items with higher indices in the array.
|
8
|
+
#
|
9
|
+
# This is an extension of ArrayComposite to include the Movable and
|
10
|
+
# ParentTracker mixins.
|
11
|
+
class ArrayBranch < ArrayComposite
|
12
|
+
include Movable
|
13
|
+
include ParentTracker
|
14
|
+
|
15
|
+
# Initialises the ArrayBranch
|
16
|
+
#
|
17
|
+
# The ArrayBranch is created with no children, no parent, and no ID.
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
# @example Creates a new ArrayBranch.
|
21
|
+
# branch = ArrayBranch.new
|
22
|
+
def initialize
|
23
|
+
super()
|
24
|
+
remove_parent
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Compo
|
2
|
+
# A simple implementation of a branch, whose children are stored in an Hash
|
3
|
+
#
|
4
|
+
# An HashBranch is a composite object that may be moved into other composite
|
5
|
+
# objects. It stores its children as an Hash, and the ID of each child is
|
6
|
+
# its hash key. Inserting and removing items into the HashBranch will not
|
7
|
+
# change the IDs of other items, but inserting with an existing key will
|
8
|
+
# remove the previous occupant.
|
9
|
+
#
|
10
|
+
# This is an extension of HashComposite to include the Movable and
|
11
|
+
# ParentTracker mixins.
|
12
|
+
class HashBranch < HashComposite
|
13
|
+
include Movable
|
14
|
+
include ParentTracker
|
15
|
+
|
16
|
+
# Initialises the HashBranch
|
17
|
+
#
|
18
|
+
# The HashBranch is created with no children, no parent, and no ID.
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
# @example Creates a new HashBranch.
|
22
|
+
# branch = HashBranch.new
|
23
|
+
def initialize
|
24
|
+
super()
|
25
|
+
remove_parent
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/compo/leaf.rb
CHANGED
@@ -3,18 +3,22 @@ require 'compo/null_composite'
|
|
3
3
|
require 'compo/parent_tracker'
|
4
4
|
|
5
5
|
module Compo
|
6
|
-
# A simple implementation of a leaf
|
6
|
+
# A simple implementation of a leaf node
|
7
7
|
#
|
8
|
-
# Leaves have no children, but can be moved to one.
|
8
|
+
# Leaves have no children, but can be moved to one. They implement the
|
9
|
+
# Composite API, but all additions and removals fail, and the Leaf always
|
10
|
+
# reports no children.
|
9
11
|
class Leaf < NullComposite
|
10
12
|
include Movable
|
11
13
|
include ParentTracker
|
12
14
|
|
13
15
|
# Initialises the Leaf
|
14
16
|
#
|
17
|
+
# The Leaf is created with no children, no parent, and no ID.
|
18
|
+
#
|
15
19
|
# @api public
|
16
20
|
# @example Creates a new Leaf.
|
17
|
-
# leaf.new
|
21
|
+
# leaf = Leaf.new
|
18
22
|
def initialize
|
19
23
|
remove_parent
|
20
24
|
end
|
data/lib/compo/parent_tracker.rb
CHANGED
data/lib/compo/version.rb
CHANGED
data/lib/compo.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
|
-
|
1
|
+
# Base mixins
|
2
2
|
require 'compo/composite'
|
3
|
-
require 'compo/hash_composite'
|
4
|
-
require 'compo/leaf'
|
5
3
|
require 'compo/movable'
|
6
|
-
require 'compo/null_composite'
|
7
4
|
require 'compo/parent_tracker'
|
5
|
+
|
6
|
+
# Composite implementations
|
7
|
+
require 'compo/array_composite'
|
8
|
+
require 'compo/hash_composite'
|
9
|
+
require 'compo/null_composite'
|
10
|
+
|
11
|
+
# Leaf and branch classes
|
12
|
+
require 'compo/array_branch'
|
13
|
+
require 'compo/hash_branch'
|
14
|
+
require 'compo/leaf'
|
15
|
+
|
16
|
+
# Misc
|
8
17
|
require 'compo/version'
|
9
18
|
|
10
|
-
# The main module for Compo
|
19
|
+
# The main module for Compo
|
11
20
|
module Compo
|
12
21
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'compo'
|
3
|
+
|
4
|
+
describe Compo::ArrayBranch do
|
5
|
+
describe '#initialize' do
|
6
|
+
it 'initialises with no parent' do
|
7
|
+
expect(subject.parent).to be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'initialises with an ID function returning nil' do
|
11
|
+
expect(subject.id).to be_nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'compo'
|
3
|
+
|
4
|
+
describe Compo::HashBranch do
|
5
|
+
describe '#initialize' do
|
6
|
+
it 'initialises with no parent' do
|
7
|
+
expect(subject.parent).to be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'initialises with an ID function returning nil' do
|
11
|
+
expect(subject.id).to be_nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,125 +1,125 @@
|
|
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.3
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backports
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
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
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: fuubar
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
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
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: yard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: yardstick
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
description: "\n Compo provides mixins and classes that assist in implementing
|
@@ -131,8 +131,8 @@ executables: []
|
|
131
131
|
extensions: []
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
|
-
- .gitignore
|
135
|
-
- .rspec
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rspec"
|
136
136
|
- CHANGELOG
|
137
137
|
- Gemfile
|
138
138
|
- LICENSE.txt
|
@@ -140,16 +140,20 @@ files:
|
|
140
140
|
- Rakefile
|
141
141
|
- compo.gemspec
|
142
142
|
- lib/compo.rb
|
143
|
+
- lib/compo/array_branch.rb
|
143
144
|
- lib/compo/array_composite.rb
|
144
145
|
- lib/compo/composite.rb
|
146
|
+
- lib/compo/hash_branch.rb
|
145
147
|
- lib/compo/hash_composite.rb
|
146
148
|
- lib/compo/leaf.rb
|
147
149
|
- lib/compo/movable.rb
|
148
150
|
- lib/compo/null_composite.rb
|
149
151
|
- lib/compo/parent_tracker.rb
|
150
152
|
- lib/compo/version.rb
|
153
|
+
- spec/array_branch_spec.rb
|
151
154
|
- spec/array_composite_spec.rb
|
152
155
|
- spec/composite_spec.rb
|
156
|
+
- spec/hash_branch_spec.rb
|
153
157
|
- spec/hash_composite_spec.rb
|
154
158
|
- spec/leaf_spec.rb
|
155
159
|
- spec/movable_spec.rb
|
@@ -166,23 +170,25 @@ require_paths:
|
|
166
170
|
- lib
|
167
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
168
172
|
requirements:
|
169
|
-
- -
|
173
|
+
- - ">="
|
170
174
|
- !ruby/object:Gem::Version
|
171
175
|
version: '0'
|
172
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
177
|
requirements:
|
174
|
-
- -
|
178
|
+
- - ">="
|
175
179
|
- !ruby/object:Gem::Version
|
176
180
|
version: '0'
|
177
181
|
requirements: []
|
178
182
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.0.
|
183
|
+
rubygems_version: 2.2.0.rc.1
|
180
184
|
signing_key:
|
181
185
|
specification_version: 4
|
182
186
|
summary: Composite pattern style mixins with IDs
|
183
187
|
test_files:
|
188
|
+
- spec/array_branch_spec.rb
|
184
189
|
- spec/array_composite_spec.rb
|
185
190
|
- spec/composite_spec.rb
|
191
|
+
- spec/hash_branch_spec.rb
|
186
192
|
- spec/hash_composite_spec.rb
|
187
193
|
- spec/leaf_spec.rb
|
188
194
|
- spec/movable_spec.rb
|