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

.build_hash(page_id = nil) ⇒ Object

class methods ##



26
27
28
29
# File 'app/models/maglev/page_path.rb', line 26

def self.build_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 ##



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

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

#pageObject

associations ##



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

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

#selfObject

callbacks ##



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

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

#valueObject

validations ##



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

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