Module: Redmine::Acts::Watchable::ClassMethods

Defined in:
lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_watchable(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 29

def acts_as_watchable(options = {})
  return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods)

  class_eval do
    has_many :watchers, :as => :watchable, :dependent => :delete_all
    has_many :watcher_users, :through => :watchers, :source => :user, :validate => false

    scope :watched_by, lambda { |principal|
      user_ids = Array(principal.id)
      user_ids |= principal.group_ids if principal.is_a?(User)
      user_ids.compact!

      joins(:watchers).
      where("#{Watcher.table_name}.user_id IN (?)", user_ids)
    }
  end
  send :include, Redmine::Acts::Watchable::InstanceMethods
end