module Hyalite::InstanceHandles

Constants

SEPARATOR

Public Class Methods

create_root_id() click to toggle source
# File lib/hyalite/instance_handles.rb, line 12
def create_root_id
  root_id_string(root_index);
end
is_ancestor_id_of(ancestor_id, descendant_id) click to toggle source
# File lib/hyalite/instance_handles.rb, line 61
def is_ancestor_id_of(ancestor_id, descendant_id)
  descendant_id.index(ancestor_id) == 0 && is_boundary(descendant_id, ancestor_id.length)
end
is_boundary(id, index) click to toggle source
# File lib/hyalite/instance_handles.rb, line 65
def is_boundary(id, index)
  id[index] == SEPARATOR || index == id.length
end
next_descendant_id(ancestor_id, destination_id) click to toggle source
# File lib/hyalite/instance_handles.rb, line 69
def next_descendant_id(ancestor_id, destination_id)
  return ancestor_id if ancestor_id == destination_id

  start = ancestor_id.length + SEPARATOR.length
  last = destination_id.index(SEPARATOR, start) || destination_id.length
  destination_id[0,last]
end
parent_id(id) click to toggle source
# File lib/hyalite/instance_handles.rb, line 57
def parent_id(id)
  id.empty? ? '' : id[0, id.rindex(SEPARATOR)]
end
root_id_from_node_id(id) click to toggle source
# File lib/hyalite/instance_handles.rb, line 16
def root_id_from_node_id(id)
  if id && id.start_with?(SEPARATOR)
    index = id.index(SEPARATOR, 1)
    index ? id[0...index] : id
  end
end
root_id_string(index) click to toggle source
# File lib/hyalite/instance_handles.rb, line 8
def root_id_string(index)
  SEPARATOR + index.to_s(36)
end
root_index() click to toggle source
# File lib/hyalite/instance_handles.rb, line 23
def root_index
  index = @root_index
  @root_index += 1
  index
end
traverse_ancestors(target_id, &cb) click to toggle source
# File lib/hyalite/instance_handles.rb, line 34
def traverse_ancestors(target_id, &cb)
  traverse_parent_path('', target_id, true, false, &cb)
end
traverse_parent_path(start, stop, skip_first, skip_last) { |id, traverse_up| ... } click to toggle source
# File lib/hyalite/instance_handles.rb, line 38
def traverse_parent_path(start, stop, skip_first, skip_last, &cb)
  start = start || ''
  stop = stop || ''
  traverse_up = is_ancestor_id_of(stop, start)

  id = start
  loop do
    unless (skip_first && id == start) || (skip_last && id == stop)
      ret = yield(id, traverse_up)
    end

    if ret == false || id == stop
      break
    end

    id = traverse_up ? parent_id(id) : next_descendant_id(id, stop)
  end
end
traverse_two_phase(target_id, &cb) click to toggle source
# File lib/hyalite/instance_handles.rb, line 29
def traverse_two_phase(target_id, &cb)
  traverse_parent_path('', target_id, true, false, &cb)
  traverse_parent_path(target_id, '', false, true, &cb)
end