Class: PagePath

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/page_path.rb

Defined Under Namespace

Classes: NoLocaleError, NoPathError, PageNotSavedError

Class Method Summary collapse

Class Method Details

.associate(page, locale: nil, path: nil) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/page_path.rb', line 34

def associate(page, locale: nil, path: nil)
  locale ||= page.locale
  path ||= page.full_path
  raise PageNotSavedError unless page.id?
  raise NoLocaleError unless locale
  raise NoPathError unless path

  page_path = get_or_create(locale, path, page)
  page_path.update(page:) unless page_path.page_id == page.id
  page_path
end

.build(page) ⇒ Object



15
16
17
18
19
20
21
22
# File 'app/models/page_path.rb', line 15

def build(page)
  page.locales.each do |locale|
    localized = page.localize(locale)
    localized.ensure_path_segment
    associate(localized) if !localized.deleted? && localized.full_path?
  end
  page.children.each { |p| build(p) }
end

.build_allObject



24
25
26
27
28
# File 'app/models/page_path.rb', line 24

def build_all
  Page.roots.each do |p|
    build(p)
  end
end

.get(locale, path) ⇒ Object



30
31
32
# File 'app/models/page_path.rb', line 30

def get(locale, path)
  find_by(locale:, path:)
end