Module: Rewritten::Document

Includes:
ActiveSupport::Inflector
Defined in:
lib/rewritten/document.rb

Instance Method Summary collapse

Instance Method Details

#pathObject



7
8
9
10
11
# File 'lib/rewritten/document.rb', line 7

def path
  plural = ActiveSupport::Inflector.pluralize(self.class.to_s)
  resources = ActiveSupport::Inflector.underscore(plural)
  "/#{resources}/#{id}"
end

#remove_rewritten_urlsObject



33
34
35
# File 'lib/rewritten/document.rb', line 33

def remove_rewritten_urls
  Rewritten.remove_all_translations(path)
end

#rewritten_urlObject



13
14
15
16
# File 'lib/rewritten/document.rb', line 13

def rewritten_url
  return '' unless persisted?
  Rewritten.get_current_translation(path)
end

#rewritten_url=(new_url) ⇒ Object



18
19
20
21
22
# File 'lib/rewritten/document.rb', line 18

def rewritten_url=(new_url)
  if !new_url.nil? && new_url != '' && new_url != rewritten_url
    Rewritten.add_translation(new_url, path)
  end
end

#rewritten_url?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rewritten/document.rb', line 29

def rewritten_url?
  Rewritten.exist_translation_for?(path)
end

#rewritten_urlsObject



24
25
26
27
# File 'lib/rewritten/document.rb', line 24

def rewritten_urls
  return [] unless persisted?
  Rewritten.get_all_translations(path)
end