Module: ActiveMetadata::Persistence::ActiveRecord::Watcher::InstanceMethods

Defined in:
lib/active_metadata/persistence/active_record/watcher.rb

Instance Method Summary collapse

Instance Method Details

#create_watcher_for(field, owner) ⇒ Object

Raises:

  • (RuntimeError)


8
9
10
11
# File 'lib/active_metadata/persistence/active_record/watcher.rb', line 8

def create_watcher_for(field, owner)
  raise RuntimeError, "The object id MUST be valued" unless self.id
  Watcher.create! :document_class => , :document_id => , :label => field, :owner_id => owner.id
end

#delete_watcher_for(field, owner) ⇒ Object



17
18
19
20
21
# File 'lib/active_metadata/persistence/active_record/watcher.rb', line 17

def delete_watcher_for(field, owner)
  Watcher.where(:document_id => , :label => field, :owner_id => owner.id).each do |watcher|
    watcher.destroy
  end   
end

#is_watched_by(field, owner) ⇒ Object



23
24
25
# File 'lib/active_metadata/persistence/active_record/watcher.rb', line 23

def is_watched_by(field,owner)
  Watcher.where(:document_class => , :document_id => , :label => field, :owner_id => owner.id).empty? ? false : true
end

#notifierObject



31
32
33
# File 'lib/active_metadata/persistence/active_record/watcher.rb', line 31

def notifier
  @notifier
end

#send_notification(field, old_value, new_value, type = :default_message, created_by = nil) ⇒ Object



27
28
29
# File 'lib/active_metadata/persistence/active_record/watcher.rb', line 27

def send_notification(field, old_value, new_value, type=:default_message, created_by=nil)   
  watchers_for(field).each { |watch| notify_changes(field, old_value, new_value, self.class.to_s, self.id, watch.owner_id, type, created_by) }
end

#watchers_for(field) ⇒ Object



13
14
15
# File 'lib/active_metadata/persistence/active_record/watcher.rb', line 13

def watchers_for(field)
  Watcher.all(:conditions => {:document_class => , :label => field, :document_id => })
end