Class: Pressroom::Category

Inherits:
ApplicationRecord show all
Includes:
Scoped, Sluggable
Defined in:
app/models/pressroom/category.rb

Constant Summary

Constants included from Sluggable

Sluggable::FALLBACK_SLUG

Constants included from Scoped

Scoped::NO_SCOPE_ID, Scoped::NO_SCOPE_TYPE

Instance Method Summary collapse

Methods included from Scoped

id_for, #scope, #scope=, #scoped?, type_for

Instance Method Details

#ancestorsObject

Nearest ancestor first, root last.



22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/pressroom/category.rb', line 22

def ancestors
  result = []
  node = parent

  while node && !result.include?(node)
    result << node
    node = node.parent
  end

  result
end

#depthObject



34
35
36
# File 'app/models/pressroom/category.rb', line 34

def depth
  ancestors.size
end