Sha256: 6fc0bd84aaa18c14c061562738244a8b27165b8c73288c4f08fb53b18707684c

Contents?: true

Size: 723 Bytes

Versions: 4

Compression:

Stored size: 723 Bytes

Contents

class Watcher
  include Mongoid::Document

  belongs_to :label

  field :owner_id, :type => Integer

  def notify_changes(matched_label, old_value, new_value, model_class, model_id)
    create_inbox_alert(User.find(owner_id).inbox, matched_label, old_value, new_value, model_class, model_id)
  end

  def create_inbox_alert(inbox, label, old_value, new_value, model_class, model_id)
    Message.create! do |message|
      message.label = label
      message.model_class = model_class.to_s
      message.model_id = model_id
      message.alert_type = :model_value_changed
      message.old_value = old_value
      message.new_value = new_value
      message.inbox_id = inbox.id
      message.read = false
    end 
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_metadata-0.2.2 lib/model/mongoid/watcher.rb
active_metadata-0.2.1 lib/model/mongoid/watcher.rb
active_metadata-0.2.0 lib/model/mongoid/watcher.rb
active_metadata-0.1.9 lib/model/mongoid/watcher.rb