Module: Gluttonberg::Content::Publishable

Included in:
Article, Blog, Gallery, Page
Defined in:
lib/gluttonberg/content/publishable.rb

Overview

A mixin that will add simple publishing functionality to any arbitrary model. This includes finders for retrieving published records and instance methods for quickly changing the state.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Add the class and instance methods, declare the property we store the published state in.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gluttonberg/content/publishable.rb', line 9

def self.included(klass)
  klass.class_eval do
    extend ClassMethods
    include InstanceMethods
    scope :published, lambda { where("state = 'published'  AND  published_at <= ?", Time.zone.now) }
    scope :archived, :conditions => { :state => "archived" }
    scope :draft, :conditions => { :state => "draft" }
    scope :non_published, :conditions => "state != 'published'"
    before_validation :clean_published_date 
  end
end