class ActivePermalink::Localizer::PermalinkBackend

Attributes

options[R]
record[R]

Public Class Methods

new(record) click to toggle source
# File lib/active_permalink/localizer.rb, line 43
def initialize(record)
  @record     = record
  @options    = record.permalink_options
  @permalinks = record.permalinks.to_a
end

Public Instance Methods

exists?(locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 53
def exists?(locale)
  enforce_available_locales!(locale)
  find_permalink(locale).present?
end
fallbacks?() click to toggle source
# File lib/active_permalink/localizer.rb, line 49
def fallbacks?
  options[:fallbacks].present?
end
read(locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 58
def read(locale)
  enforce_available_locales!(locale)
  find_slug(locale)
end
write(value, locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 63
def write(value, locale)
  enforce_available_locales!(locale)
  update_slug(value, locale)
end

Private Instance Methods

enforce_available_locales!(locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 70
def enforce_available_locales!(locale)
  return unless I18n.enforce_available_locales
  return if I18n.available_locales.include?(locale.to_sym)

  raise InvalidLocale.new(locale)
end
find_fallback(locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 88
def find_fallback(locale)
  locales = I18n.fallbacks[locale]
  find_permalink(*locales) if locales.present?
end
find_slug(locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 93
def find_slug(locale)
  permalink = find_permalink(locale)
  permalink = find_fallback(locale) if permalink.blank?

  permalink.try(:slug)
end
locale_column() click to toggle source
# File lib/active_permalink/localizer.rb, line 77
def locale_column
  @options[:locale_column]
end
update_slug(value, locale) click to toggle source
# File lib/active_permalink/localizer.rb, line 100
def update_slug(value, locale)
  Generator.generate(record, value, locale)
  @permalinks = record.permalinks.to_a
end