modular_tree 0.7.0 → 0.9.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
  SHA256:
3
- metadata.gz: 70c50cd21f7eb027dcb0560bb164268c929860f61e2912dfbb1a0fd1576f5869
4
- data.tar.gz: 120a0efd4e6dda689412e3618267645e4252ba6b24c8949203162a2c0b979fdf
3
+ metadata.gz: '08649719e3acd43aaaba027428bce680e0e376a5d11192357b5fb8078795a704'
4
+ data.tar.gz: '08cb0635c2ec27a4f29390bdecddbe1484f5d48dc1f180faf6b07d7122802ac1'
5
5
  SHA512:
6
- metadata.gz: 62af79315ea3ec5c46e47b9e8cd1807b0f6dd33ee914d1a12b37cf8e0006bd2a2be6381e033e1883da88884bcae2e4ffb5a4e66b4d3ca3026d09721ba4e5c9d0
7
- data.tar.gz: 12a75c54c67fd37c920ec4c663cd6199038c713c86d79f14a11143432f79ab1621115e0af7a1266dfecb8a56e5c073d8bf5e30b485e17af21accf840c78f7b4c
6
+ metadata.gz: d2766c613470299bebff94a45aad0b386221e7a1eb159833f5d13f7c4015949687cede5cc71ed08b190f3fc7b0d24677e3e01d8ebc78f950c8fed4fadc1b7500
7
+ data.tar.gz: fec9a23e683d539ba8a92510aaf4c0f0ae3c1fb64cfcac05a91f254ae49c937969a5eb83e042f5f5b4faf592b9781b24b83bffd4991ded8653f7fc8d47e34a53
@@ -1,5 +1,9 @@
1
1
  module Tree
2
- # For internal trees with a global namespace for nodes
2
+ # A pool assumes objects has a unique identifier
3
+ #
4
+ # Pool adds a @pool class variable to the including class and all of its
5
+ # subclasses
6
+ #
3
7
  module Pool
4
8
  include PathAlgorithms
5
9
 
@@ -9,19 +13,25 @@ module Tree
9
13
  super
10
14
  end
11
15
 
12
- def initialize(_parent)
16
+ def initialize(*args)
13
17
  super
14
- self.class[self.uid] = self
18
+ !self.class.uid?(self.uid) or raise TreeError, "Duplicate UID: #{self.uid}"
19
+ self.class.send(:[]=, self.uid, self)
15
20
  end
16
21
 
17
22
  module ClassMethods
18
- def key?(uid) = @pool.key?(uid)
19
- def keys = @pool.keys
23
+ def uid?(uid) = @pool.key?(uid)
24
+ def uids = @pool.keys
20
25
  def nodes = @pool.values
21
26
  def size = @pool.size
22
27
  def empty? = @pool.empty?
23
28
  def [](uid) = @pool[uid]
24
29
  def []=(uid, node) @pool[uid] = node end
30
+
31
+ def inherited(subclass)
32
+ subclass.instance_variable_set(:@pool, @pool)
33
+ super
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.7.0"
4
+ VERSION = "0.9.0"
5
5
  end
data/lib/modular_tree.rb CHANGED
@@ -8,6 +8,10 @@ include Constrain
8
8
  require 'forward_to'
9
9
  include ForwardTo
10
10
 
11
+ module Tree
12
+ class TreeError < RuntimeError; end
13
+ end
14
+
11
15
  require_relative "modular_tree/version"
12
16
  require_relative "modular_tree/separator"
13
17
  require_relative "modular_tree/matcher"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modular_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-17 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constrain