Sha256: 9dd74e261b741e813c706ac043cb33832c53cc0ad0d425999bb482504cf619bf

Contents?: true

Size: 963 Bytes

Versions: 1

Compression:

Stored size: 963 Bytes

Contents

module Gluttonberg
  module Blog
    class CommentSubscription < ActiveRecord::Base
      self.table_name = "gb_comment_subscriptions"

      before_save    :generate_reference_hash
      belongs_to     :article

      attr_accessible :article_id , :author_email , :author_name
      MixinManager.load_mixins(self)

      def self.notify_subscribers_of(article , comment)
        subscribers = self.where(:article_id => article.id).all
        subscribers.each do |subscriber|
          unless subscriber.author_email == comment.writer_email
            BlogNotifier.delay.comment_notification(subscriber , article , comment )
            comment.notification_sent_at = Time.now
            comment.save
          end
        end
      end

      def generate_reference_hash
        unless self.reference_hash
          self.reference_hash = Digest::SHA1.hexdigest(Time.now.to_s + self.author_email + self.article_id.to_s)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gluttonberg-blog-1.0.0 app/models/gluttonberg/blog/comment_subscription.rb