Sha256: bc2fb32eebc1f5fd51b14d45a2d20e1c7870395ad7aa2047f6c88f866133af92

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

module Enki
  class Comment < ActiveRecord::Base
    DEFAULT_LIMIT = 15
    
    extend PaginationShim

    belongs_to            :post
    
    attr_accessible       :author, :author_url, :author_email, :body, :post, :created_at, :body_html, :updated_at

    before_save           :apply_filter
    after_save            :denormalize
    after_destroy         :denormalize

    validates_presence_of :author, :body, :post

    def apply_filter
      self.body_html = Lesstile.format_as_xhtml(self.body, :code_formatter => Lesstile::CodeRayFormatter)
    end

    def trusted_user?
      false
    end

    def user_logged_in?
      false
    end

    def approved?
      true
    end

    def denormalize
      self.post.denormalize_comments_count!
    end

    def destroy_with_undo
      undo_item = nil
      transaction do
        self.destroy
        undo_item = DeleteCommentUndo.create_undo(self)
      end
      undo_item
    end

    # Delegates
    def post_title
      post.title
    end

    class << self
      def protected_attribute?(attribute)
        [:author, :body].include?(attribute.to_sym)
      end

      def new_with_filter(params)
        comment = Comment.new(params)
        comment.created_at = Time.now
        comment.apply_filter
        comment
      end

      def build_for_preview(params)
        Comment.new_with_filter(params)
      end

      def find_recent(options = {})
        find(:all, {
          :limit => DEFAULT_LIMIT,
          :order => 'created_at DESC'
        }.merge(options))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enki-engine-0.0.5 app/models/enki/comment.rb
enki-engine-0.0.4 app/models/enki/comment.rb
enki-engine-0.0.3 app/models/enki/comment.rb
enki-engine-0.0.2 app/models/enki/comment.rb