require 'exa/version' require 'exa/tree_node' require 'exa/visitor' module Exa class Process def initialize(title) @title = title end def register Process.table += [ self ] end def unregister Process.table -= [ self ] end def run! register perform! unregister end def self.table @table ||= [] end end class Copier < Process def initialize(source, target) @source = source @target = target super("copy #{source} -> #{target}") end def perform! @target.update @source.value end end class Deleter < Process def initialize(target) @target = target super("delete #{target}") end def perform! @target.parent.remove_child(child_name: @target.name) end end class << self def remember(path, value) p [ :remember, path: path, value: value ] recall(path).update(value) end alias :[]= :remember def recall(path) p [ :recall, path: path ] visitor.seek(path) end alias :[] :recall def expand(path) visitor.query(path) end alias :call :expand def clean_slate! @root = TreeNode.new(name: '', value: '(root)') # @visitor = Visitor.new(@root) end private def visitor Visitor.new(root) end def root @root ||= TreeNode.new(name: '', value: '(system root)') end end end