Class: ActivePermalink::Localizer::PermalinkBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/active_permalink/localizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ PermalinkBackend

Returns a new instance of PermalinkBackend.



43
44
45
46
47
# File 'lib/active_permalink/localizer.rb', line 43

def initialize(record)
  @record     = record
  @options    = record.permalink_options
  @permalinks = record.permalinks.to_a
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



41
42
43
# File 'lib/active_permalink/localizer.rb', line 41

def options
  @options
end

Returns the value of attribute permalinks.



41
42
43
# File 'lib/active_permalink/localizer.rb', line 41

def permalinks
  @permalinks
end

#recordObject (readonly)

Returns the value of attribute record.



41
42
43
# File 'lib/active_permalink/localizer.rb', line 41

def record
  @record
end

Instance Method Details

#exists?(locale) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/active_permalink/localizer.rb', line 53

def exists?(locale)
  enforce_available_locales!(locale)
  find_permalink(locale).present?
end

#fallbacks?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/active_permalink/localizer.rb', line 49

def fallbacks?
  options[:fallbacks].present?
end

#read(locale) ⇒ Object



58
59
60
61
# File 'lib/active_permalink/localizer.rb', line 58

def read(locale)
  enforce_available_locales!(locale)
  find_slug(locale)
end

#write(value, locale, **options) ⇒ Object



63
64
65
66
# File 'lib/active_permalink/localizer.rb', line 63

def write(value, locale, **options)
  enforce_available_locales!(locale)
  update_slug(value, locale, **options)
end