modular_tree 0.6.0 → 0.8.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: b6913b33ae629fa98c3832ba7ae313e9948c581a53811d49648233f349b85b64
4
- data.tar.gz: eaaec7d8f9f85924c3064c18b5a88c7805baa0c70e2a7db21e798d217348b67f
3
+ metadata.gz: 29780afe3a4d0303217b66719daebdc62292f504a4581f19e11bac43c131a92b
4
+ data.tar.gz: d712c143c16fa5957b03bd4f5a21b8e6e6a48e6ef3c09597d8f25ab3ed596a02
5
5
  SHA512:
6
- metadata.gz: de1721efbd56c4fe8abdfb54f7d044273daf1938612e4316ef6d1344bc9b1e13bddda02da8f8b0f757d75e45f27a20674b365f28c5ecbc19c53c269217a2d7e5
7
- data.tar.gz: a9c68cf3df5204e568a575b1e510fa8974cd39baddead8a52f83edceee865284729a808e8065c898a1e717f2dc7ddfccc1b7a74056c50ff9e368199780c84e29
6
+ metadata.gz: b94f7f70d4777df66e1a4391ac55aa9117e23d8fc389763d3959c7b9650e1572a39bf73e6b05ce522b0371276cb8e7eba024594cc9b688ef36d1a497cfc9a87f
7
+ data.tar.gz: 75ab4ec990bcf11d1f18b056eb0c1579b4fa58a7af241c7e270641bf4762085eb063428c995c390cd5baecb8df69ec6435e3609f626746a5313ed627fc607e65
@@ -80,9 +80,11 @@ module Tree
80
80
  # Filter children. Doesn't recurse. If a block is given, it should return
81
81
  # truish to select a child node
82
82
  #
83
+ # The match expression can also be a list of classes (instead of an array of classes)
84
+ #
83
85
  # TODO: Maybe make #children an Array extended with filtering
84
- def choose(match_expr = nil, &block)
85
- matcher = Matcher.new(match_expr, &block)
86
+ def choose(*args, &block)
87
+ matcher = Matcher.new(*args, &block)
86
88
  if block_given?
87
89
  a = []
88
90
  each_branch { |branch, key| a << branch if matcher.match? branch }
@@ -27,7 +27,8 @@ module Tree
27
27
  end
28
28
  end
29
29
 
30
- def initialize(expr = nil, &block)
30
+ def initialize(*args, &block)
31
+ expr = args.size == 1 ? args.first : args
31
32
  constrain expr, Proc, Symbol, Class, [Class], true, false, nil
32
33
  expr.nil? == block_given? or raise ArgumentError, "Expected either an argument or a block"
33
34
  @expr = (expr.nil? ? block : expr)
@@ -1,5 +1,8 @@
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
3
6
  module Pool
4
7
  include PathAlgorithms
5
8
 
@@ -9,9 +12,9 @@ module Tree
9
12
  super
10
13
  end
11
14
 
12
- def initialize(_parent)
15
+ def initialize(*args)
13
16
  super
14
- self.class[self.uid] = self
17
+ self.class.send(:[]=, self.uid, self)
15
18
  end
16
19
 
17
20
  module ClassMethods
@@ -22,6 +25,11 @@ module Tree
22
25
  def empty? = @pool.empty?
23
26
  def [](uid) = @pool[uid]
24
27
  def []=(uid, node) @pool[uid] = node end
28
+
29
+ def inherited(subclass)
30
+ subclass.instance_variable_set(:@pool, @pool)
31
+ super
32
+ end
25
33
  end
26
34
  end
27
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modular_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen