Class: Maglev::PagePath

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.canonical_value_hash(page_id = nil) ⇒ Object

class methods ##



43
44
45
46
# File 'app/models/maglev/page_path.rb', line 43

def self.canonical_value_hash(page_id = nil)
  query = page_id ? where(maglev_page_id: page_id) : all
  query.canonical.pluck(:locale, :value).to_h
end

Instance Method Details

#canonicalObject

scopes ##



25
# File 'app/models/maglev/page_path.rb', line 25

scope :canonical, -> { where(canonical: true) }

#pageObject

associations ##



22
# File 'app/models/maglev/page_path.rb', line 22

belongs_to :page, class_name: 'Maglev::Page', foreign_key: 'maglev_page_id', inverse_of: :paths

#selfObject

callbacks ##



36
# File 'app/models/maglev/page_path.rb', line 36

after_initialize -> { self.locale ||= Maglev::I18n.current_locale }

#valueObject

validations ##



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

validates :value, presence: true, exclusion: { in: Maglev.config.reserved_paths }