class Exa::TreeNode
Attributes
links[R]
name[R]
overlays[R]
parent[R]
Public Class Methods
new(name:, value: nil, parent: nil, virtual: false, symbolic: false)
click to toggle source
# File lib/exa/tree_node.rb, line 4 def initialize(name:, value: nil, parent: nil, virtual: false, symbolic: false) p [ :tree_node, name: name ] @name = name @value = value @parent = parent @virtual = virtual @symbolic = symbolic @children = [] @overlays = [] @links = [] end
Public Instance Methods
children()
click to toggle source
# File lib/exa/tree_node.rb, line 86 def children if virtual? virtualize(constituents.flat_map(&:children)) else @children + symbolize(symbolic_children) + virtualize(virtual_children) end end
copy(target)
click to toggle source
# File lib/exa/tree_node.rb, line 103 def copy(target) Copier.new(self, target).perform! end
create_child(child_name:)
click to toggle source
# File lib/exa/tree_node.rb, line 60 def create_child(child_name:) child = TreeNode.new(name: child_name, parent: self) @children << child child end
delete()
click to toggle source
# File lib/exa/tree_node.rb, line 107 def delete Deleter.new(self).perform! end
inspect()
click to toggle source
# File lib/exa/tree_node.rb, line 34 def inspect "<#{@name}>" end
link(source:)
click to toggle source
# File lib/exa/tree_node.rb, line 81 def link(source:) @links << source self end
path()
click to toggle source
# File lib/exa/tree_node.rb, line 38 def path if symbolic? dereference_symbolic_link.path else if @parent slash_name = "/#@name" if @parent.path == '/' slash_name else @parent.path + slash_name end else '/' #@name end end end
query(path)
click to toggle source
# File lib/exa/tree_node.rb, line 99 def query(path) Visitor.new(self).query(path) end
recall(path)
click to toggle source
# File lib/exa/tree_node.rb, line 94 def recall(path) Visitor.new(self).seek(path) end
Also aliased as: []
remove_child(child_name:)
click to toggle source
# File lib/exa/tree_node.rb, line 66 def remove_child(child_name:) child = @children.detect { |c| c.name == child_name } @children.delete(child) self end
symbolic?()
click to toggle source
# File lib/exa/tree_node.rb, line 30 def symbolic? @symbolic end
unify(overlay:)
click to toggle source
# File lib/exa/tree_node.rb, line 72 def unify(overlay:) if overlay.virtual? raise "Won't union mount virtual paths! (Try `link(source: ...)` instead.)" end @overlays << overlay self end
update(val)
click to toggle source
# File lib/exa/tree_node.rb, line 55 def update(val) @value = val self end
value()
click to toggle source
# File lib/exa/tree_node.rb, line 16 def value if virtual? constituents.first.value elsif symbolic? dereference_symbolic_link.value else @value end end
virtual?()
click to toggle source
# File lib/exa/tree_node.rb, line 26 def virtual? @virtual end
Protected Instance Methods
constituents()
click to toggle source
# File lib/exa/tree_node.rb, line 112 def constituents sources = if parent.virtual? parent.constituents.flat_map(&:children) else parent.overlays.flat_map(&:children) end sources.select do |candidate| candidate.name == @name end end
dereference_symbolic_link()
click to toggle source
# File lib/exa/tree_node.rb, line 133 def dereference_symbolic_link # okay, we're symbolic... so our parents created us # and have a link parent.links.flat_map(&:children).detect do |linked_child| linked_child.name == @name end end
symbolic_children()
click to toggle source
# File lib/exa/tree_node.rb, line 128 def symbolic_children # this is really a reference @links.flat_map(&:children) end
virtual_children()
click to toggle source
# File lib/exa/tree_node.rb, line 124 def virtual_children @overlays.flat_map(&:children) end
Private Instance Methods
symbolize(schildren)
click to toggle source
# File lib/exa/tree_node.rb, line 142 def symbolize(schildren) schildren.map(&method(:symbolize_one)) end
symbolize_one(schild)
click to toggle source
# File lib/exa/tree_node.rb, line 146 def symbolize_one(schild) TreeNode.new(name: schild.name, value: schild.value, parent: self, symbolic: true) end
virtualize(vchildren)
click to toggle source
# File lib/exa/tree_node.rb, line 150 def virtualize(vchildren) vchildren.map(&method(:virtualize_one)) end
virtualize_one(vchild)
click to toggle source
# File lib/exa/tree_node.rb, line 154 def virtualize_one(vchild) TreeNode.new(name: vchild.name, value: vchild.value, parent: self, virtual: true) end