Module: LoyalCore::ActsAsTree::InstanceMethods

Defined in:
lib/loyal_core/acts/tree.rb

Instance Method Summary collapse

Instance Method Details

#children?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/loyal_core/acts/tree.rb', line 35

def children?
  self.children_count > 0
end

#tree_ancestor_idsObject

祖先



40
41
42
# File 'lib/loyal_core/acts/tree.rb', line 40

def tree_ancestor_ids
  self.ancestors.map(&:id).uniq.sort
end

#tree_descendant_idsObject

子孙后代



58
59
60
# File 'lib/loyal_core/acts/tree.rb', line 58

def tree_descendant_ids
  self.descendants.map(&:id).uniq.sort
end

#tree_self_and_ancestor_idsObject



44
45
46
# File 'lib/loyal_core/acts/tree.rb', line 44

def tree_self_and_ancestor_ids
  self.self_and_ancestors.map(&:id).uniq.sort
end

#tree_self_and_descendant_idsObject

子孙后代 包括自己



63
64
65
# File 'lib/loyal_core/acts/tree.rb', line 63

def tree_self_and_descendant_ids
  self.self_and_descendants.map(&:id).uniq.sort
end

#tree_self_and_siblings_idsObject



53
54
55
# File 'lib/loyal_core/acts/tree.rb', line 53

def tree_self_and_siblings_ids
  self.self_and_siblings_ids.map(&:id).uniq.sort
end

#tree_sibling_idsObject

同一个父母的孩子



49
50
51
# File 'lib/loyal_core/acts/tree.rb', line 49

def tree_sibling_ids
  self.siblings.map(&:id).uniq.sort
end