Sha256: c30cea00402626c926b9add638ef3a81d2dd28b96ac54bc200785e28a705da39

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8
module Sunrise
  module Models
    module Post
      def self.included(base)
        base.send :include, InstanceMethods
        base.send :extend,  ClassMethods
      end
      
      module ClassMethods
        def self.extended(base)
          base.send(:include, Utils::Header)
          base.class_eval do
            belongs_to :structure
            has_many :comments, :as => :commentable, :dependent => :delete_all
            
            validates_presence_of :title, :content
	
	          before_save :make_date
          end
        end
      end
      
      module InstanceMethods
      
        def content_without_html
          return nil if self.content.blank?
          self.content.no_html
        end
        
        protected
    
          def make_date
            self.published_at ||= Time.now
      
            self.year  = self.published_at.year  if respond_to?(:year)
            self.month = self.published_at.month if respond_to?(:month)
            self.day   = self.published_at.day   if respond_to?(:day)
          end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sunrise-posts-0.1.2 lib/sunrise/models/post.rb
sunrise-posts-0.1.1 lib/sunrise/models/post.rb
sunrise-posts-0.1.0 lib/sunrise/models/post.rb