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

Defined in:
lib/active_metadata/persistence/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/watcher.rb', line 8

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

#delete_watcher_for(field, owner) ⇒ Object



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

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

#is_watched_by(field, owner) ⇒ Object



29
30
31
# File 'lib/active_metadata/persistence/watcher.rb', line 29

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

#notifierObject



37
38
39
# File 'lib/active_metadata/persistence/watcher.rb', line 37

def notifier
  @notifier
end

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



33
34
35
# File 'lib/active_metadata/persistence/watcher.rb', line 33

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

return all the watches related to a passed field. query always match for the current model matches are returned grouped by owner and contains records that define or not a particular model instance watching



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

def watchers_for(field)
  ActiveMetadata::Watcher.select("distinct(owner_id)").where(
      "model_class = :model_class AND label = :label AND (model_id = :model_id OR model_id IS NULL)",
      { :model_class => , :label => field, :model_id =>  }
      )
end