Class: Slugged::Slug

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/slugged/slug.rb

Class Method Summary collapse

Class Method Details

.id_for(scope, slug) ⇒ Object



13
14
15
# File 'lib/slugged/slug.rb', line 13

def self.id_for(scope, slug)
  ordered.for_slug(scope, slug).pluck(:record_id).first
end

.previous_for(record) ⇒ Object



17
18
19
# File 'lib/slugged/slug.rb', line 17

def self.previous_for(record)
  ordered.only_slug.for_record(record).pluck(:slug)
end

.record_slug(record, slug) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/slugged/slug.rb', line 30

def self.record_slug(record, slug)
  scope = Slugged.key_for_scope(record)
  # Clear slug history in this scope before recording the new slug
  for_slug(scope, slug).delete_all
  new.tap do |history|
    history.scope     = scope
    history.record_id = record.id
    history.slug      = slug.to_s
    history.save
  end
end

.remove_history_for(record) ⇒ Object



42
43
44
# File 'lib/slugged/slug.rb', line 42

def self.remove_history_for(record)
  for_record(record).delete_all
end

.usable?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/slugged/slug.rb', line 46

def self.usable?
  table_exists? rescue false
end