Class: DagMe::Adapters::Base
- Inherits:
-
Object
- Object
- DagMe::Adapters::Base
- Defined in:
- lib/dag_me/adapters/base.rb
Overview
The reachability interface. The model layer only talks to this; whether answers come from the materialized closure or a recursive CTE is an adapter concern.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #ancestors(node) ⇒ Object
-
#apply_topological_order(relation) ⇒ Object
Orders a relation so ancestors always precede descendants.
-
#between(ancestor, descendant) ⇒ Object
Nodes on any path from
ancestortodescendant, endpoints included: self_and_descendants(ancestor) ∩ self_and_ancestors(descendant). - #descendants(node) ⇒ Object
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
- #model ⇒ Object
-
#reachable?(ancestor, descendant) ⇒ Boolean
True when
ancestorreachesdescendantthrough one or more edges. - #self_and_ancestors(node) ⇒ Object
- #self_and_descendants(node) ⇒ Object
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
11 12 13 |
# File 'lib/dag_me/adapters/base.rb', line 11 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/dag_me/adapters/base.rb', line 9 def config @config end |
Instance Method Details
#ancestors(node) ⇒ Object
19 20 21 |
# File 'lib/dag_me/adapters/base.rb', line 19 def ancestors(node) raise NotImplementedError end |
#apply_topological_order(relation) ⇒ Object
Orders a relation so ancestors always precede descendants. Both adapters sort by global ancestor count: for any edge u -> v, ancestors(v) ⊇ ancestors(u) ∪ u, so the count strictly increases along every edge - a valid topological order for any sub-relation.
50 51 52 |
# File 'lib/dag_me/adapters/base.rb', line 50 def apply_topological_order(relation) raise NotImplementedError end |
#between(ancestor, descendant) ⇒ Object
Nodes on any path from ancestor to descendant, endpoints included:
self_and_descendants(ancestor) ∩ self_and_ancestors(descendant).
42 43 44 |
# File 'lib/dag_me/adapters/base.rb', line 42 def between(ancestor, descendant) self_and_descendants(ancestor).and(self_and_ancestors(descendant)) end |
#descendants(node) ⇒ Object
23 24 25 |
# File 'lib/dag_me/adapters/base.rb', line 23 def descendants(node) raise NotImplementedError end |
#model ⇒ Object
15 16 17 |
# File 'lib/dag_me/adapters/base.rb', line 15 def model config.model end |
#reachable?(ancestor, descendant) ⇒ Boolean
True when ancestor reaches descendant through one or more edges.
36 37 38 |
# File 'lib/dag_me/adapters/base.rb', line 36 def reachable?(ancestor, descendant) raise NotImplementedError end |
#self_and_ancestors(node) ⇒ Object
27 28 29 |
# File 'lib/dag_me/adapters/base.rb', line 27 def self_and_ancestors(node) raise NotImplementedError end |
#self_and_descendants(node) ⇒ Object
31 32 33 |
# File 'lib/dag_me/adapters/base.rb', line 31 def self_and_descendants(node) raise NotImplementedError end |