Module: Redmine::Acts::Watchable::InstanceMethods

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary

Instance Method Summary

Class Method Details

+ (Object) included(base)



28
29
30
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 28

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

- (Object) add_watcher(user)

Adds user as a watcher



38
39
40
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 38

def add_watcher(user)
  self.watchers << Watcher.new(:user => user)
end

- (Object) addable_watcher_users

Returns an array of users that are proposed as watchers



33
34
35
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 33

def addable_watcher_users
  self.project.users.sort - self.watcher_users
end

- (Object) remove_watcher(user)

Removes user from the watchers list



43
44
45
46
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 43

def remove_watcher(user)
  return nil unless user && user.is_a?(User)
  Watcher.delete_all "watchable_type = '#{self.class}' AND watchable_id = #{self.id} AND user_id = #{user.id}"
end

- (Object) set_watcher(user, watching = true)

Adds/removes watcher



49
50
51
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 49

def set_watcher(user, watching=true)
  watching ? add_watcher(user) : remove_watcher(user)
end

- (Boolean) watched_by?(user)

Returns true if object is watched by user

Returns:

  • (Boolean)


54
55
56
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 54

def watched_by?(user)
  !!(user && self.watchers.detect {|w| w.user_id == user.id })
end

- (Object) watcher_recipients

Returns an array of watchers’ email addresses



59
60
61
62
63
64
65
# File 'vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb', line 59

def watcher_recipients
  notified = watchers.collect(&:user).select(&:active?)
  if respond_to?(:visible?)
    notified.reject! {|user| !visible?(user)}
  end
  notified.collect(&:mail).compact
end