Module: SimpleNestedSet::Inspect

Defined in:
lib/simple_nested_set/inspect.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.line(node, indent, last) ⇒ Object



23
24
25
# File 'lib/simple_nested_set/inspect.rb', line 23

def line(node, indent, last)
  "#{indent}#{last ? '' : ''}── #{node.class.name} id: #{node.id}\n"
end

.next_indent(indent, last) ⇒ Object



27
28
29
# File 'lib/simple_nested_set/inspect.rb', line 27

def next_indent(indent, last)
  "#{indent}#{last ? '    ' : '|   '}"
end

.tree(nodes, indent = '') ⇒ Object



15
16
17
18
19
20
21
# File 'lib/simple_nested_set/inspect.rb', line 15

def tree(nodes, indent = '')
  nodes.inject('') do |out, node|
    last = node == nodes.last
    out << line(node, indent, last)
    out << tree(node.children, next_indent(indent, last))
  end
end

Instance Method Details

#inspect_tree(attributes = [:id, :lft, :rgt, :parent_id, :slug, :path, :level]) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/simple_nested_set/inspect.rb', line 5

def inspect_tree(attributes = [:id, :lft, :rgt, :parent_id, :slug, :path, :level])
  if is_a?(Class)
    nodes = all
    ".\n" << with_exclusive_scope { Inspect.tree(nodes) }
  else
    ".\n" << Inspect.tree([self])
  end
end