Sha256: afcbbf6625d44c2ebd8c6fae0a3cf9d2caa9ffcb3293e26679b42125cbe28c30

Contents?: true

Size: 515 Bytes

Versions: 3

Compression:

Stored size: 515 Bytes

Contents

module Hitchens
  class Post < ActiveRecord::Base
    default_scope order('publication_date desc')
    scope :published, lambda{ where('publication_date < ?', Time.now) }

    def published=(value)
      if ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
        self.publication_date = Time.now unless publication_date
      else
        self.publication_date = nil
      end
    end
    def published
      return false unless publication_date
      publication_date < Time.now
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hitchens-0.0.3 app/models/hitchens/post.rb
hitchens-0.0.2 app/models/hitchens/post.rb
hitchens-0.0.1 app/models/hitchens/post.rb