Sha256: 311bd7d60124ea7ce8328a9e9c35188adf83b3e134e4b1593628697c7f510abe

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8
module Freeberry
  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, HeaderUtils)
          base.class_eval do
            belongs_to :structure
            has_many :comments, :as => :commentable, :dependent => :delete_all
            has_slug
            
            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
freeberry-0.3.0 lib/freeberry/models/post.rb
freeberry-0.2.9 lib/freeberry/models/post.rb
freeberry-0.2.7 lib/freeberry/models/post.rb