Module: HasHierarchy::Path

Extended by:
ActiveSupport::Concern
Defined in:
lib/has_hierarchy/path.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#ancestor_of?(node) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/has_hierarchy/path.rb', line 34

def ancestor_of?(node)
  node.path_parts.include?(path_part)
end

#depthObject



42
43
44
# File 'lib/has_hierarchy/path.rb', line 42

def depth
  path_parts.size
end

#descendant_of?(node) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/has_hierarchy/path.rb', line 38

def descendant_of?(node)
  path_parts.include?(node.path_part)
end

#full_pathObject



54
55
56
# File 'lib/has_hierarchy/path.rb', line 54

def full_path
  path + path_part
end

#pathObject



46
47
48
# File 'lib/has_hierarchy/path.rb', line 46

def path
  self[path_column]
end

#path=(path) ⇒ Object



50
51
52
# File 'lib/has_hierarchy/path.rb', line 50

def path=(path)
  self[path_column] = path
end

#rootObject



24
25
26
27
28
# File 'lib/has_hierarchy/path.rb', line 24

def root
  if root_part = path_parts.first
    self.class.find_by(path_part_column => root_part)
  end
end

#root_of?(node) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/has_hierarchy/path.rb', line 30

def root_of?(node)
  node.path_parts.first == path_part if path_part.present?
end