Module: SnapshotTree::ActsAsTree
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/snapshot_tree/acts_as_tree.rb
Defined Under Namespace
Modules: ClassMethods
Classes: TreeHelper
Instance Method Summary
collapse
Instance Method Details
#ancestor_nodes(*args) ⇒ Object
11
12
13
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 11
def ancestor_nodes(*args)
self.class.ancestor_nodes(id, *args)
end
|
#child_nodes(*args) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 35
def child_nodes(*args)
opts = args.detect { |x| x.is_a?(Hash) }
opts ? opts.merge!(depth: 1) : args << {depth: 1}
descendent_nodes(*args)
end
|
#descendent_nodes(*args) ⇒ Object
Also known as:
descendant_nodes
5
6
7
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 5
def descendent_nodes(*args)
self.class.descendent_nodes(id, *args)
end
|
#leaf_node?(*args) ⇒ Boolean
19
20
21
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 19
def leaf_node?(*args)
self.class.leaf_nodes(id, *args).where(id: id).size > 0
end
|
#parent_node(*args) ⇒ Object
31
32
33
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 31
def parent_node(*args)
ancestor_nodes(*args).try(:last)
end
|
#root_node(*args) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 23
def root_node(*args)
if root_node?(*args)
self
else
ancestor_nodes(*args).limit(1).first
end
end
|
#root_node?(*args) ⇒ Boolean
15
16
17
|
# File 'lib/snapshot_tree/acts_as_tree.rb', line 15
def root_node?(*args)
self.class.root_nodes(id, *args).where(id: id).size > 0
end
|