Class: Publinator::Publication

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/publinator/publication.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_by_slug(slug) ⇒ Object



54
55
56
# File 'app/models/publinator/publication.rb', line 54

def self.get_by_slug(slug)
  self.published.where(:slug => slug)
end

Instance Method Details

#collectionObject



24
25
26
27
28
29
# File 'app/models/publinator/publication.rb', line 24

def collection
  return unless collection_publishable_type_id
  pt = Publinator::PublishableType.find(collection_publishable_type_id)
  return if !pt
  pt.name.constantize.send(collection_scope.to_sym)
end

#contentObject



31
32
33
# File 'app/models/publinator/publication.rb', line 31

def content
  publishable_type.constantize.find(publishable_id)
end

#generate_slugObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/publinator/publication.rb', line 35

def generate_slug
  if self.slug.blank? || slug =~ /temporary_slug\d?/
    if default
      self.slug = 'index'
    elsif custom_slug.present?
      self.slug = custom_slug
    elsif publishable.present? && publishable.title.present?
      self.slug = self.publishable.title.strip.downcase.gsub(/[^a-zA-Z0-9\-\_]/, '_')
      self.slug = self.slug.gsub("___", "_")
      self.slug = self.slug.gsub("__", "_")
      if slug.end_with?("_")
        self.slug = self.slug.chop
      end
    else
      self.slug = "temporary_slug_#{rand(100000)}"
    end
  end
end