unotifier 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ec61a1237c2bdcf5f22b0f272805090d1a82f4e83dee871c3daa01bef627d5c
4
- data.tar.gz: 8d0c39f00d10c01a8b452c2b1a29c7f995f144993e491102004f73f65488426e
3
+ metadata.gz: aaa686f0cd41483a94d0746b9538177adae345674774b7e7798cb507c9c2b61c
4
+ data.tar.gz: 5e61daf30bfe7dbbdd62a0edb5f2cad5c2383e5ad3dc83482ad1cec0b61781c1
5
5
  SHA512:
6
- metadata.gz: 6d5bce4be79ee89ca014fdde94eb48ba55829dddefd86a8250d90e2c94ee244c49a70dcabf7fe8ff09b24d8e31c5cd92b2ef4dcb019fed6c4b8accbfda851f35
7
- data.tar.gz: e087624c1ccfc08495ea06e2e8c53993c16f2c30f4fcfa017d51279da0f6f2a5bead5f7146d36c6543207edb1c41de155db8f3257d80498f1ac7643a22a8d07a
6
+ metadata.gz: 21fc2a10954d1a2c5e0fa1d6ae7eafc9ad199d02ec634b850c90393604669b5ee63e0d617985859507ed1eaf8787cbc1db227b7791e698308d8142d7b02d476a
7
+ data.tar.gz: e96f359477dde1299d359a646b0efda3c40fba6a42c546e4dc1758e7df8bd39f663b4a89f5b61778678130ba9ba0d349ea1ccd430de22fceda4f317729b6a167
data/.rubocop.yml ADDED
@@ -0,0 +1,151 @@
1
+ require: rubocop-rails
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - "bin/**/*"
6
+ - "spec/**/*"
7
+ - "*.gemspec"
8
+ - "Gemfile"
9
+ - "Rakefile"
10
+
11
+ Rails:
12
+ Enabled: true
13
+
14
+ Layout/BlockAlignment:
15
+ EnforcedStyleAlignWith: start_of_block
16
+
17
+ Layout/FirstArrayElementIndentation:
18
+ EnforcedStyle: consistent
19
+
20
+ Layout/FirstHashElementIndentation:
21
+ EnforcedStyle: consistent
22
+
23
+ Layout/LineLength:
24
+ AutoCorrect: false
25
+ Max: 110
26
+
27
+ Layout/MultilineOperationIndentation:
28
+ EnforcedStyle: aligned
29
+
30
+ Layout/SpaceInLambdaLiteral:
31
+ EnforcedStyle: require_space
32
+
33
+ Lint/InheritException:
34
+ EnforcedStyle: standard_error
35
+
36
+ Lint/SuppressedException:
37
+ Enabled: false
38
+
39
+ Metrics/AbcSize:
40
+ Enabled: false
41
+
42
+ Metrics/BlockLength:
43
+ Enabled: false
44
+
45
+ Metrics/BlockNesting:
46
+ Max: 6
47
+
48
+ Metrics/ClassLength:
49
+ Enabled: false
50
+
51
+ Metrics/CyclomaticComplexity:
52
+ Enabled: false
53
+
54
+ Metrics/MethodLength:
55
+ Enabled: false
56
+
57
+ Naming/MethodParameterName:
58
+ AllowedNames: ["by", "e", "id", "to", "tx", "fn", "tz"]
59
+
60
+ Metrics/ModuleLength:
61
+ Enabled: false
62
+
63
+ Metrics/PerceivedComplexity:
64
+ Enabled: false
65
+
66
+ Naming/PredicateName:
67
+ Enabled: false
68
+
69
+ Rails/DynamicFindBy:
70
+ Enabled: false
71
+
72
+ Rails/EnumHash:
73
+ Enabled: false
74
+
75
+ Rails/HttpStatus:
76
+ EnforcedStyle: numeric
77
+
78
+ Rails/LexicallyScopedActionFilter:
79
+ Enabled: false
80
+
81
+ Rails/ReversibleMigration:
82
+ Enabled: false
83
+
84
+ Rails/SafeNavigation:
85
+ ConvertTry: true
86
+
87
+ Rails/SkipsModelValidations:
88
+ Enabled: false
89
+
90
+ Rails/TimeZone:
91
+ Enabled: false
92
+
93
+ Rails/UnknownEnv:
94
+ Environments: ["development", "test", "staging", "staging_unmerged", "testnet", "production"]
95
+
96
+ Security/YAMLLoad:
97
+ Enabled: false
98
+
99
+ Style/CollectionMethods:
100
+ Enabled: true
101
+
102
+ Style/Documentation:
103
+ Enabled: false
104
+
105
+ Style/DoubleNegation:
106
+ Enabled: false
107
+
108
+ Style/FormatStringToken:
109
+ Enabled: false
110
+
111
+ Style/FrozenStringLiteralComment:
112
+ Enabled: false
113
+
114
+ Style/GlobalVars:
115
+ Enabled: false
116
+
117
+ Style/MultilineIfModifier:
118
+ Enabled: false
119
+
120
+ Style/NumericPredicate:
121
+ EnforcedStyle: comparison
122
+
123
+ Style/PercentLiteralDelimiters:
124
+ PreferredDelimiters:
125
+ default: "()"
126
+ "%i": "()"
127
+ "%I": "()"
128
+ "%r": "{}"
129
+ "%w": "()"
130
+ "%W": "()"
131
+
132
+ Style/PreferredHashMethods:
133
+ Enabled: false
134
+
135
+ Style/RedundantSelf:
136
+ Enabled: false
137
+
138
+ Style/RegexpLiteral:
139
+ EnforcedStyle: slashes
140
+
141
+ Style/StringLiterals:
142
+ EnforcedStyle: double_quotes
143
+
144
+ Style/StringLiteralsInInterpolation:
145
+ EnforcedStyle: double_quotes
146
+
147
+ Style/TrailingCommaInArrayLiteral:
148
+ EnforcedStyleForMultiline: comma
149
+
150
+ Style/TrailingCommaInHashLiteral:
151
+ EnforcedStyleForMultiline: comma
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unotifier (0.2.10)
4
+ unotifier (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -44,4 +44,4 @@ DEPENDENCIES
44
44
  unotifier!
45
45
 
46
46
  BUNDLED WITH
47
- 1.17.1
47
+ 1.17.3
data/lib/configuration.rb CHANGED
@@ -2,6 +2,7 @@ module UNotifier
2
2
  class Configuration
3
3
  attr_accessor :site_providers
4
4
  attr_accessor :external_providers
5
+ attr_accessor :system_providers
5
6
  attr_accessor :resource_class
6
7
  attr_accessor :notifications_path
7
8
  attr_accessor :localization_provider
@@ -9,6 +10,7 @@ module UNotifier
9
10
  def initialize
10
11
  @site_providers = []
11
12
  @external_providers = []
13
+ @system_providers = []
12
14
  @resource_class = nil
13
15
  @notifications_path = nil
14
16
  @localization_provider = nil
data/lib/exceptions.rb CHANGED
@@ -1,6 +1,27 @@
1
1
  module UNotifier
2
2
  class UNotifierError < StandardError; end
3
3
 
4
+ class EmptyLocaleKeyError < UNotifierError
5
+ attr_reader :key
6
+
7
+ def initialize(key)
8
+ @key = key
9
+ message = ":locale_key parameter is required for fetching '#{key}' locale"
10
+ super(message)
11
+ end
12
+ end
13
+
14
+ class AttributeMissingError < UNotifierError
15
+ attr_reader :key, :attribute
16
+
17
+ def initialize(key, attribute)
18
+ @key = key
19
+ @attribute = attribute
20
+ message = "Missing '#{attribute}' attribute for notification '#{key}'"
21
+ super(message)
22
+ end
23
+ end
24
+
4
25
  class NotificationsConfigNotFoundError < UNotifierError
5
26
  attr_reader :path, :absolute_path
6
27
 
@@ -33,16 +54,6 @@ module UNotifier
33
54
  end
34
55
  end
35
56
 
36
- class EmptyLocaleKeyError < UNotifierError
37
- attr_reader :key
38
-
39
- def initialize(key)
40
- @key = key
41
- message = ":locale_key parameter is required for fetching '#{key}' locale"
42
- super(message)
43
- end
44
- end
45
-
46
57
  class UnknownLocaleKeyError < UNotifierError
47
58
  attr_reader :key, :locale_key, :options
48
59
 
data/lib/hash.rb CHANGED
@@ -1,6 +1,19 @@
1
+ # rubocop:disable Style/ClassAndModuleChildren
1
2
  class ::Hash
2
3
  def deep_merge!(second)
3
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
4
- self.merge!(second.to_h, &merger)
4
+ merger = proc do |_, v1, v2|
5
+ if v1.is_a?(Hash) && v2.is_a?(Hash)
6
+ v1.merge(v2, &merger)
7
+ elsif v1.is_a?(Array) && v2.is_a?(Array)
8
+ v1 | v2
9
+ elsif [:undefined, nil, :nil].include?(v2)
10
+ v1
11
+ else
12
+ v2
13
+ end
14
+ end
15
+
16
+ self.merge!(second.to_h, &merger)
5
17
  end
6
18
  end
19
+ # rubocop:enable Style/ClassAndModuleChildren
@@ -5,9 +5,10 @@ module UNotifier
5
5
  @notification_conditions = notification_conditions
6
6
  end
7
7
 
8
- def can_notify?(target)
8
+ def can_notify?(notification)
9
9
  return true if @notification_conditions.empty?
10
- @notification_conditions.all? { |c| c.call(target) }
10
+
11
+ @notification_conditions.all? { |c| c.call(notification) }
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,22 @@
1
+ module UNotifier
2
+ module Provider
3
+ module System
4
+ class ActionCable < ProviderBase
5
+ attr_reader :server
6
+ attr_accessor :channel_name
7
+
8
+ def initialize(server, channel_name: nil, notification_conditions: [])
9
+ super(notification_conditions: notification_conditions)
10
+ @server = server
11
+ @channel_name = channel_name
12
+ end
13
+
14
+ def notify(notification, data)
15
+ return unless can_notify?(notification)
16
+
17
+ server.broadcast channel_name.call(notification), data
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module UNotifier
2
+ module Provider
3
+ module User
4
+ class ActionCable < ProviderBase
5
+ attr_reader :server
6
+ attr_accessor :autohide_delay, :channel_name
7
+
8
+ def initialize(server, channel_name: nil, autohide_delay: 30, notification_conditions: [])
9
+ super(notification_conditions: notification_conditions)
10
+ @server = server
11
+ @channel_name = channel_name
12
+ @autohide_delay = autohide_delay
13
+ end
14
+
15
+ def notify(notification)
16
+ return unless can_notify?(notification)
17
+
18
+ server.broadcast channel_name.call(notification), serialize_notification(notification)
19
+ end
20
+
21
+ def serialize_notification(notification)
22
+ {
23
+ id: notification.id,
24
+ title: notification.title,
25
+ body: notification.body,
26
+ autohide_delay: notification.autohide_delay || @autohide_delay,
27
+ user_login: notification.target.login,
28
+ link: notification.link,
29
+ urgency: notification.urgency,
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module UNotifier
2
+ module Provider
3
+ module User
4
+ class ActionMailer < ProviderBase
5
+ def initialize(mailer, sending_method: :new_notification, notification_conditions: [])
6
+ super(notification_conditions: notification_conditions)
7
+ @mailer = mailer
8
+ @sending_method = sending_method
9
+ end
10
+
11
+ def notify(notification)
12
+ return unless can_notify?(notification)
13
+
14
+ sending_method =
15
+ if @sending_method.is_a?(Array)
16
+ @sending_method.map { |m| m.call(notification) }&.first
17
+ else
18
+ @sending_method
19
+ end
20
+
21
+ @mailer.public_send(sending_method, notification).deliver
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/provider.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative "provider/provider_base"
2
- require_relative "provider/action_cable"
3
- require_relative "provider/action_mailer"
2
+ require_relative "provider/system/action_cable"
3
+ require_relative "provider/user/action_cable"
4
+ require_relative "provider/user/action_mailer"
4
5
 
5
6
  module UNotifier
6
7
  module Provider
data/lib/settings.rb CHANGED
@@ -1,28 +1,36 @@
1
1
  module UNotifier
2
2
  class Settings
3
- DEFAULT_URGENCY = "external"
3
+ DEFAULT_URGENCY = "external".freeze
4
4
 
5
5
  def self.customizable?(config)
6
- %w(regular optional).include?(config["urgency"])
6
+ (
7
+ config.key?("urgency") &&
8
+ %w(regular optional).include?(config["urgency"])
9
+ ) || (
10
+ config.key?("target") &&
11
+ config["target"].values.any? { |c| customizable?(c) }
12
+ )
7
13
  end
8
14
 
9
15
  def self.filter_customizable(config)
10
- config.map do |key, subkeys|
11
- filtered = subkeys.select do |subkey, value|
12
- (value.has_key?("urgency") && customizable?(value)) ||
13
- (value.has_key?("target") && value["target"].values.any? { |subvalue| customizable?(subvalue) })
14
- end
15
-
16
- filtered = filtered.each_with_object({}) do |(subkey, value), out|
17
- out[subkey] = value["urgency"] ||
18
- value["target"]
16
+ customizable = config.map do |key, subkeys|
17
+ filtered =
18
+ subkeys
19
+ .select { |_, value| value.key?("user") }
20
+ .map { |subkey, value| [subkey, value["user"]] }
21
+ .select { |_, value| customizable?(value) }
22
+ .each_with_object({}) do |(subkey, value), out|
23
+ out[subkey] = value["urgency"] ||
24
+ value["target"]
19
25
  .select { |_, subvalue| customizable?(subvalue) }
20
26
  .map { |_, subvalue| subvalue["urgency"] }
21
27
  .first
22
- end
28
+ end
23
29
 
24
30
  [key, filtered]
25
- end.to_h.select { |_, subkeys| !subkeys.empty? }
31
+ end
32
+
33
+ customizable.to_h.reject { |_, subkeys| subkeys.empty? }
26
34
  end
27
35
 
28
36
  def self.keys_from(config)
@@ -36,8 +44,6 @@ module UNotifier
36
44
  end
37
45
  end
38
46
 
39
- private
40
-
41
47
  def self.flatten_keys(keys)
42
48
  keys.map do |key, subkeys|
43
49
  subkeys.map do |subkey, urgency|
@@ -0,0 +1,28 @@
1
+ module UNotifier
2
+ module SystemNotifier
3
+ def self.notify_system(notification, params = {})
4
+ key = notification.key
5
+ config = UNotifier.load_notification!(key)
6
+ return if config["system"].nil?
7
+
8
+ # Raise only when we're sure that config has "system" block
9
+ raise AttributeMissingError.new(key, "system") unless params
10
+
11
+ data = config["system"]["keys"].each_with_object({}) do |(head, attributes), obj|
12
+ head = head.to_sym
13
+ attributes = attributes.map(&:to_sym)
14
+ raise AttributeMissingError.new(key, head) unless params.key?(head)
15
+
16
+ attributes.each { |a| raise AttributeMissingError.new(key, a) unless params[head].keys.include?(a) }
17
+
18
+ obj[head] = params[head].slice(*attributes)
19
+ end
20
+
21
+ data.merge!(key: notification.key)
22
+
23
+ UNotifier.configuration.system_providers.each do |provider|
24
+ provider.notify notification, data
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,59 @@
1
+ module UNotifier
2
+ module UserNotifier
3
+ def self.notify_user(notification, params = {})
4
+ locale_key = UNotifier.locale_key_for(notification.key, params)
5
+ user_settings = notification.target.notification_settings[notification.key]
6
+ user_settings ||= Settings::DEFAULT_URGENCY
7
+
8
+ notify_with = []
9
+
10
+ if !params[:external_only] && notify_onsite?(notification, user_settings)
11
+ notify_with += UNotifier.configuration.site_providers
12
+ end
13
+
14
+ if !params[:onsite_only] && notify_external?(notification, user_settings)
15
+ notify_with += UNotifier.configuration.external_providers
16
+ end
17
+
18
+ notify_with.each do |provider|
19
+ title_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.title"
20
+ body_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.body"
21
+
22
+ if UNotifier.configuration.localization_provider.exists?(title_provider_key)
23
+ notification.title =
24
+ UNotifier.configuration.localization_provider.t(
25
+ title_provider_key, params.merge(locale: notification.target.locale)
26
+ )
27
+ end
28
+
29
+ if UNotifier.configuration.localization_provider.exists?(body_provider_key)
30
+ notification.body =
31
+ UNotifier.configuration.localization_provider.t(
32
+ body_provider_key, params.merge(locale: notification.target.locale, default: "")
33
+ )
34
+ end
35
+
36
+ provider.notify(notification)
37
+ end
38
+ end
39
+
40
+ def self.notify_onsite?(notification, user_settings)
41
+ return false if notification.urgency == "optional" && user_settings == "off"
42
+
43
+ notification.target.online?
44
+ end
45
+
46
+ def self.notify_external?(notification, user_settings)
47
+ case notification.urgency
48
+ when "immediate"
49
+ true
50
+ when "regular", "optional"
51
+ user_settings == "external" && !notification.target.online?
52
+ when "onsite"
53
+ false
54
+ else
55
+ false
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module UNotifier
2
- VERSION = "0.2.10"
2
+ VERSION = "0.3.0".freeze
3
3
  end
data/lib/unotifier.rb CHANGED
@@ -2,6 +2,8 @@ require "yaml"
2
2
 
3
3
  require_relative "hash"
4
4
  require_relative "unotifier/version"
5
+ require_relative "unotifier/system_notifier"
6
+ require_relative "unotifier/user_notifier"
5
7
  require_relative "exceptions"
6
8
  require_relative "provider"
7
9
  require_relative "configuration"
@@ -21,7 +23,7 @@ module UNotifier
21
23
  end
22
24
 
23
25
  def self.notifications_config
24
- @notifications_config ||= if configuration.notifications_path.kind_of?(Array)
26
+ @notifications_config ||= if configuration.notifications_path.is_a?(Array)
25
27
  configuration.notifications_path.each_with_object({}) do |path, config|
26
28
  config.deep_merge!(YAML.load_file(path))
27
29
  end
@@ -29,7 +31,7 @@ module UNotifier
29
31
  YAML.load_file(configuration.notifications_path)
30
32
  end
31
33
  rescue Errno::ENOENT
32
- raise NotificationsConfigNotFoundError.new(configuration.notifications_path)
34
+ raise NotificationsConfigNotFoundError, configuration.notifications_path
33
35
  end
34
36
 
35
37
  def self.reload!
@@ -38,68 +40,62 @@ module UNotifier
38
40
  end
39
41
 
40
42
  def self.load_notification(key)
41
- notifications_config.dig(*key.split('.'))
43
+ notifications_config.dig(*key.split("."))
42
44
  end
43
45
 
44
46
  def self.load_notification!(key)
45
47
  notification = load_notification(key)
46
- raise NotificationNotFoundError.new(key) unless notification
47
- notification
48
- end
49
-
50
- def self.urgency_for(key, params = {})
51
- config = load_notification!(key)
48
+ raise NotificationNotFoundError, key unless notification
52
49
 
53
- if config["target"].kind_of?(Hash)
54
- urgency = config.dig("target", params[:target], "urgency")
55
- raise UnknownTargetError.new(key, params[:target]) unless urgency
56
- urgency
57
- else
58
- config["urgency"]
59
- end
50
+ notification
60
51
  end
61
52
 
62
53
  def self.locale_key_for(key, params = {})
63
- config = load_notification!(key)
54
+ config = load_notification!(key)["user"]
55
+
56
+ if config["locale_options"].is_a?(Array)
57
+ raise EmptyLocaleKeyError, key unless params[:locale_key]
64
58
 
65
- if config["locale_options"].kind_of?(Array)
66
- raise EmptyLocaleKeyError.new(key) unless params[:locale_key]
67
59
  raise UnknownLocaleKeyError.new(
68
60
  key, params[:locale_key], config["locale_options"]
69
61
  ) unless config["locale_options"].include?(params[:locale_key])
62
+
70
63
  "notifications.#{key}.#{params[:locale_key]}"
71
64
  else
72
65
  "notifications.#{key}"
73
66
  end
74
67
  end
75
68
 
76
- def self.notify(key, target, params = {})
77
- user_settings = target.notification_settings[key]
78
- user_settings ||= Settings::DEFAULT_URGENCY
69
+ def self.notify(key, recepients, params = {})
70
+ targets = recepients.is_a?(Enumerable) ? recepients : [recepients]
71
+
72
+ targets.each do |target|
73
+ notify_target(key, target, params)
74
+ end
75
+ end
76
+
77
+ def self.notify_target(key, target, params = {})
79
78
  locale_key = locale_key_for(key, params)
80
79
  urgency = urgency_for(key, params)
81
80
 
82
81
  notification = configuration.resource_class.new(
83
82
  key: key,
84
83
  target: target,
85
- title: configuration.localization_provider.t("#{locale_key}.title", params.merge(locale: target.locale)),
86
- body: configuration.localization_provider.t("#{locale_key}.body", params.merge(locale: target.locale, default: "")),
87
84
  link: params[:link],
88
85
  autohide_delay: params[:autohide_delay],
89
- urgency: urgency
86
+ urgency: urgency,
87
+ title: configuration.localization_provider.t(
88
+ "#{locale_key}.title", params.merge(locale: target.locale)
89
+ ),
90
+ body: configuration.localization_provider.t(
91
+ "#{locale_key}.body", params.merge(locale: target.locale, default: "")
92
+ )
90
93
  )
94
+
91
95
  notification.save!
92
96
 
93
- notify_with = []
94
- notify_with += configuration.site_providers if !params[:external_only] && notify_onsite?(notification, user_settings)
95
- notify_with += configuration.external_providers if !params[:onsite_only] && notify_external?(notification, user_settings)
96
- notify_with.each do |provider|
97
- title_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.title"
98
- body_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.body"
99
- notification.title = configuration.localization_provider.t(title_provider_key, params.merge(locale: target.locale)) if configuration.localization_provider.exists?(title_provider_key)
100
- notification.body = configuration.localization_provider.t(body_provider_key, params.merge(locale: target.locale, default: "")) if configuration.localization_provider.exists?(body_provider_key)
101
- provider.notify(notification)
102
- end
97
+ UserNotifier.notify_user(notification, params)
98
+ SystemNotifier.notify_system(notification, params[:system])
103
99
  end
104
100
 
105
101
  def self.notify_onsite(key, target, params)
@@ -121,23 +117,16 @@ module UNotifier
121
117
  end
122
118
  end
123
119
 
124
- private
120
+ def self.urgency_for(key, params = {})
121
+ config = load_notification!(key)["user"]
125
122
 
126
- def self.notify_onsite?(notification, user_settings)
127
- return false if notification.urgency == "optional" && user_settings == "off"
128
- notification.target.online?
129
- end
123
+ if config["target"].is_a?(Hash)
124
+ urgency = config.dig("target", params[:target], "urgency")
125
+ raise UnknownTargetError.new(key, params[:target]) unless urgency
130
126
 
131
- def self.notify_external?(notification, user_settings)
132
- case notification.urgency
133
- when "immediate"
134
- true
135
- when "regular", "optional"
136
- user_settings == "external" && !notification.target.online?
137
- when "onsite"
138
- false
127
+ urgency
139
128
  else
140
- false
129
+ config["urgency"]
141
130
  end
142
131
  end
143
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unotifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mgpnd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
11
+ date: 2020-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ extensions: []
106
106
  extra_rdoc_files: []
107
107
  files:
108
108
  - ".gitignore"
109
+ - ".rubocop.yml"
109
110
  - Gemfile
110
111
  - Gemfile.lock
111
112
  - LICENSE.txt
@@ -119,11 +120,14 @@ files:
119
120
  - lib/exceptions.rb
120
121
  - lib/hash.rb
121
122
  - lib/provider.rb
122
- - lib/provider/action_cable.rb
123
- - lib/provider/action_mailer.rb
124
123
  - lib/provider/provider_base.rb
124
+ - lib/provider/system/action_cable.rb
125
+ - lib/provider/user/action_cable.rb
126
+ - lib/provider/user/action_mailer.rb
125
127
  - lib/settings.rb
126
128
  - lib/unotifier.rb
129
+ - lib/unotifier/system_notifier.rb
130
+ - lib/unotifier/user_notifier.rb
127
131
  - lib/unotifier/version.rb
128
132
  - unotifier.gemspec
129
133
  homepage: https://gitlab.com/hodlhodl-public/unotifier
@@ -148,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
152
  - !ruby/object:Gem::Version
149
153
  version: '0'
150
154
  requirements: []
151
- rubygems_version: 3.0.3
155
+ rubygems_version: 3.0.6
152
156
  signing_key:
153
157
  specification_version: 4
154
158
  summary: Ultimate user notification tool for web apps
@@ -1,36 +0,0 @@
1
- module UNotifier
2
- module Provider
3
- class ActionCable < ProviderBase
4
- attr_reader :server
5
- attr_accessor :autohide_delay, :channel_name
6
-
7
- def initialize(server, channel_name: nil, autohide_delay: 30, notification_conditions: [])
8
- super(notification_conditions: notification_conditions)
9
- @server = server
10
- @autohide_delay = autohide_delay
11
- @channel_name =
12
- channel_name ||
13
- -> (notification) { "notifications_for_user_#{notification.target.login}" }
14
- end
15
-
16
- def notify(notification)
17
- return unless can_notify?(notification)
18
- if notification.target.online?
19
- @server.broadcast @channel_name.call(notification), serialize_notification(notification)
20
- end
21
- end
22
-
23
- def serialize_notification(notification)
24
- {
25
- id: notification.id,
26
- title: notification.title,
27
- body: notification.body,
28
- autohide_delay: notification.autohide_delay || @autohide_delay,
29
- user_login: notification.target.login,
30
- link: notification.link,
31
- urgency: notification.urgency,
32
- }
33
- end
34
- end
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- module UNotifier
2
- module Provider
3
- class ActionMailer < ProviderBase
4
- def initialize(mailer, sending_method: :new_notification, notification_conditions: [])
5
- super(notification_conditions: notification_conditions)
6
- @mailer = mailer
7
- @sending_method = sending_method
8
- end
9
-
10
- def notify(notification)
11
- return unless can_notify?(notification)
12
- sending_method = if @sending_method.kind_of?(Array)
13
- @sending_method.map { |m| m.call(notification) }&.first
14
- else
15
- @sending_method
16
- end
17
- @mailer.public_send(sending_method, notification).deliver
18
- end
19
- end
20
- end
21
- end