BigW Consortium Gitlab

notification.rb 1.26 KB
Newer Older
1 2 3 4 5 6 7
class Notification
  #
  # Notification levels
  #
  N_DISABLED = 0
  N_PARTICIPATING = 1
  N_WATCH = 2
8
  N_GLOBAL = 3
9
  N_MENTION = 4
10

11
  attr_accessor :target
12

13 14
  class << self
    def notification_levels
15
      [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH]
16 17 18 19 20 21 22
    end

    def options_with_labels
      {
        disabled: N_DISABLED,
        participating: N_PARTICIPATING,
        watch: N_WATCH,
23
        mention: N_MENTION,
24 25 26 27 28
        global: N_GLOBAL
      }
    end

    def project_notification_levels
29
      [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH, N_GLOBAL]
30
    end
31 32 33 34
  end

  def initialize(target)
    @target = target
35 36 37
  end

  def disabled?
38
    target.notification_level == N_DISABLED
39 40 41
  end

  def participating?
42
    target.notification_level == N_PARTICIPATING
43 44 45
  end

  def watch?
46 47 48 49 50
    target.notification_level == N_WATCH
  end

  def global?
    target.notification_level == N_GLOBAL
51
  end
52

53 54 55 56
  def mention?
    target.notification_level == N_MENTION
  end

57 58 59
  def level
    target.notification_level
  end
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  
  def to_s
    case level
    when N_DISABLED
      'Disabled'
    when N_PARTICIPATING
      'Participating'
    when N_WATCH
      'Watching'
    when N_MENTION
      'On mention'
    when N_GLOBAL
      'Global'
    else
      # do nothing      
    end
  end
77
end