compo 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6db898fd60a7a46a30a7d851bd634c2be59a1d4
4
- data.tar.gz: 78d2ccf08de768e42ca7df43a29f6491b0adbcfb
3
+ metadata.gz: de0ae1a9f06c21a0818cb86865d5bd26d79aa7e0
4
+ data.tar.gz: 7cce675b54964af406c7391913fde1b8f6741c34
5
5
  SHA512:
6
- metadata.gz: 1694942f4173cd3c464a66d904ff36044ea714c79c8e2c8fc708d7c2d296dd28da42d760ebae89442c3734bf692fbf7ee3feceeebeecab5d00ce0d47ffa75f20
7
- data.tar.gz: 1c7db6618f24c57980ad14b6200cd212d516d4c800e5718fe46964576eb9ec6175c06d3a1337997507fe972ba70da7b3bcd92d396026e527a99301217b1e3d17
6
+ metadata.gz: 075f6b9688444e1ee13333c97fddf7fce91d897ac4088df6e56fa9c1a5cce5e75b2a279ed2ecbc89999d72da57e95d380f830490a847c7a288586ef06b32abce
7
+ data.tar.gz: 6900ffec47c87b03f12de21196b2a603b54569882a5e20ee682e5eca555740d2e33ee887f102142f447406ccd6a32dea89e3fe253a9057178ac4bcac91d3a0b9
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 0.3.0 (2014-05-21)
2
+ - Require bundler 1.6.
3
+ - Remove some unnecessary checks for nil: Parentless should be used instead.
4
+ (This could be construed as a backwards incompatibility, hence the version
5
+ bump.)
6
+ - Factor out branch mixins into a new Branch mixin.
7
+ - Some Rubocop fixes.
8
+
1
9
  0.2.0 (2013-12-29)
2
10
  - (BACKWARDS INCOMPATIBILITY) Implement Parentless as a null object for the
3
11
  result of calling #parent on a parentless child. This case now returns
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
- task :default => :spec
7
- task :test => :spec
6
+ task default: :spec
7
+ task test: :spec
data/compo.gemspec CHANGED
@@ -2,28 +2,29 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'compo/version'
5
+ require 'English'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = 'compo'
8
9
  spec.version = Compo::VERSION
9
10
  spec.authors = ['Matt Windsor']
10
11
  spec.email = ['matt.windsor@ury.org.uk']
11
- spec.description = %q{
12
+ spec.description = %q(
12
13
  Compo provides mixins and classes that assist in implementing a variant of
13
14
  the Composite design pattern, in which each child has an ID that uniquely
14
15
  identifies it inside the parent's child set.
15
- }
16
+ )
16
17
  spec.summary = 'Composite pattern style mixins with IDs'
17
18
  spec.homepage = 'http://github.com/CaptainHayashi/compo'
18
19
  spec.license = 'MIT'
19
20
 
20
- spec.files = `git ls-files`.split($/)
21
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
22
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
23
24
  spec.require_paths = ['lib']
24
25
 
25
26
  spec.add_development_dependency 'backports'
26
- spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'bundler', '~> 1.6'
27
28
  spec.add_development_dependency 'fuubar'
28
29
  spec.add_development_dependency 'rake'
29
30
  spec.add_development_dependency 'rspec'
@@ -1,3 +1,5 @@
1
+ require 'compo/branch'
2
+
1
3
  module Compo
2
4
  # A simple implementation of a branch, whose children are stored in an Array
3
5
  #
@@ -9,20 +11,6 @@ module Compo
9
11
  # This is an extension of ArrayComposite to include the Movable and
10
12
  # ParentTracker mixins.
11
13
  class ArrayBranch < ArrayComposite
12
- include Movable
13
- include ParentTracker
14
- include UrlReferenceable
15
-
16
- # Initialises the ArrayBranch
17
- #
18
- # The ArrayBranch is created with no children, no parent, and no ID.
19
- #
20
- # @api public
21
- # @example Creates a new ArrayBranch.
22
- # branch = ArrayBranch.new
23
- def initialize
24
- super()
25
- remove_parent
26
- end
14
+ include Branch
27
15
  end
28
16
  end
@@ -0,0 +1,18 @@
1
+ require 'compo/movable'
2
+ require 'compo/parent_tracker'
3
+ require 'compo/url_referenceable'
4
+
5
+ module Compo
6
+ # A movable, URL referenceable parent tracker
7
+ #
8
+ # A Branch represents a fully-featured part of a composite object. This
9
+ # abstract pattern is implemented concretely by Leaf (a Branch with no
10
+ # children), ArrayBranch (a Branch with a list of numerically identified
11
+ # children), and HashBranch (a Branch with a hash of key-identified children).
12
+ # reports no children.
13
+ module Branch
14
+ include Movable
15
+ include ParentTracker
16
+ include UrlReferenceable
17
+ end
18
+ end
@@ -116,7 +116,7 @@ module Compo
116
116
  #
117
117
  # @return [void]
118
118
  def remove_parent_of(child)
119
- Parentless.new.add(nil, child) unless child.nil?
119
+ Parentless.for(child)
120
120
  end
121
121
 
122
122
  # Default implementation of #remove! in terms of #remove_id!
@@ -1,3 +1,5 @@
1
+ require 'compo/branch'
2
+
1
3
  module Compo
2
4
  # A simple implementation of a branch, whose children are stored in an Hash
3
5
  #
@@ -10,20 +12,6 @@ module Compo
10
12
  # This is an extension of HashComposite to include the Movable and
11
13
  # ParentTracker mixins.
12
14
  class HashBranch < HashComposite
13
- include Movable
14
- include ParentTracker
15
- include UrlReferenceable
16
-
17
- # Initialises the HashBranch
18
- #
19
- # The HashBranch is created with no children, no parent, and no ID.
20
- #
21
- # @api public
22
- # @example Creates a new HashBranch.
23
- # branch = HashBranch.new
24
- def initialize
25
- super()
26
- remove_parent
27
- end
15
+ include Branch
28
16
  end
29
17
  end
data/lib/compo/leaf.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'compo/movable'
1
+ require 'compo/branch'
2
2
  require 'compo/null_composite'
3
3
  require 'compo/parent_tracker'
4
4
 
@@ -9,19 +9,6 @@ module Compo
9
9
  # Composite API, but all additions and removals fail, and the Leaf always
10
10
  # reports no children.
11
11
  class Leaf < NullComposite
12
- include Movable
13
- include ParentTracker
14
- include UrlReferenceable
15
-
16
- # Initialises the Leaf
17
- #
18
- # The Leaf is created with no children, no parent, and no ID.
19
- #
20
- # @api public
21
- # @example Creates a new Leaf.
22
- # leaf = Leaf.new
23
- def initialize
24
- remove_parent
25
- end
12
+ include Branch
26
13
  end
27
14
  end
data/lib/compo/movable.rb CHANGED
@@ -35,7 +35,7 @@ module Compo
35
35
  #
36
36
  # @return [void]
37
37
  def move_from_old_parent
38
- parent.remove(self) unless parent.nil?
38
+ parent.remove(self)
39
39
  end
40
40
 
41
41
  # Performs the move to a new parent, if necessary
@@ -7,12 +7,14 @@ module Compo
7
7
  # This implements #parent, #update_parent and #remove_parent to track the
8
8
  # current parent and ID function as instance variables. It also implements
9
9
  # #parent, and #id in terms of the ID function.
10
- #
11
- # Subclasses should call #remove_parent in their #initialize methods, to
12
- # set the parent and ID function to their default, empty values.
13
10
  module ParentTracker
14
11
  extend Forwardable
15
12
 
13
+ def initialize
14
+ super()
15
+ remove_parent
16
+ end
17
+
16
18
  # Gets this object's current ID
17
19
  #
18
20
  # @api public
@@ -47,6 +49,9 @@ module Compo
47
49
  #
48
50
  # @return [void]
49
51
  def update_parent(new_parent, new_id_function)
52
+ fail 'Parent cannot be nil: use #remove_parent.' if new_parent.nil?
53
+ fail 'ID function cannot be nil: use -> { nil }.' if new_id_function.nil?
54
+
50
55
  @parent = new_parent
51
56
  @id_function = new_id_function
52
57
  end
@@ -10,6 +10,25 @@ module Compo
10
10
  class Parentless
11
11
  include Composite
12
12
 
13
+ # Creates a new instance of Parentless and adds an item to it
14
+ #
15
+ # This effectively removes the item's parent.
16
+ #
17
+ # If this method is passed nil, then nothing happens.
18
+ #
19
+ # @api public
20
+ # @example Makes a new Parentless for an item.
21
+ # Parentless.for(item)
22
+ # @example Does nothing.
23
+ # Parentless.for(nil)
24
+ #
25
+ # @param item [Object] The item to be reparented to a Parentless.
26
+ #
27
+ # @return [void]
28
+ def self.for(item)
29
+ new.add(nil, item) unless item.nil?
30
+ end
31
+
13
32
  # 'Removes' a child from this Parentless
14
33
  #
15
34
  # This always succeeds, and never triggers any other action.
@@ -9,6 +9,8 @@ module Compo
9
9
  # This module expects its includer to define #parent and #id. These are
10
10
  # defined, for example, by the Compo::ParentTracker mixin.
11
11
  module UrlReferenceable
12
+ extend Forwardable
13
+
12
14
  # Returns the URL of this object
13
15
  #
14
16
  # The #url of a Composite is defined inductively as '' for composites that
@@ -61,8 +63,6 @@ module Compo
61
63
  #
62
64
  # @return [String] The URL of this object's parent, or nil if there is no
63
65
  # parent.
64
- def parent_url
65
- parent.nil? ? nil : parent.url
66
- end
66
+ def_delegator :parent, :url, :parent_url
67
67
  end
68
68
  end
data/lib/compo/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # The current gem version. See CHANGELOG for information.
2
2
  module Compo
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -40,15 +40,12 @@ shared_examples 'a URL referenceable object' do
40
40
  end
41
41
 
42
42
  describe '#parent_url' do
43
- context 'when the UrlReferenceable has no parent' do
43
+ context 'when the UrlReferenceable has a nil parent' do
44
44
  let(:parent) { nil }
45
45
 
46
- specify { expect(subject.parent_url).to be_nil }
47
-
48
- it 'calls #parent' do
49
- expect(subject).to receive(:parent)
50
- subject.parent_url
51
- end
46
+ # Note that having a nil parent is considered an error in itself.
47
+ # Parentless objects should use Parentless as a null object.
48
+ specify { expect { subject.parent_url }.to raise_error }
52
49
  end
53
50
 
54
51
  context 'when the UrlReferenceable has a parent' do
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.2.0
4
+ version: 0.3.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: 2013-12-29 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backports
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '1.6'
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: '1.3'
40
+ version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fuubar
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +142,7 @@ files:
142
142
  - lib/compo.rb
143
143
  - lib/compo/array_branch.rb
144
144
  - lib/compo/array_composite.rb
145
+ - lib/compo/branch.rb
145
146
  - lib/compo/composite.rb
146
147
  - lib/compo/hash_branch.rb
147
148
  - lib/compo/hash_composite.rb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  requirements: []
193
194
  rubyforge_project:
194
- rubygems_version: 2.2.0.rc.1
195
+ rubygems_version: 2.2.2
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: Composite pattern style mixins with IDs