unotifier 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/settings.rb +28 -5
- data/lib/unotifier.rb +9 -4
- data/lib/unotifier/system_notifier.rb +8 -0
- data/lib/unotifier/user_notifier.rb +4 -1
- data/lib/unotifier/version.rb +1 -1
- metadata +3 -11
- data/bin/console +0 -10
- data/bin/rake +0 -29
- data/bin/rspec +0 -29
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a81b0764d3f887d08ea60520f2905dc87582adb3ac6c7dd80a5b9b1008fd3f1
|
4
|
+
data.tar.gz: 0e1172c73283881a6e8a08c3006e2c28a4686f4a20631df6c0d759fcecf8aa35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0023a587bb451a35ee378fb14e00c3ec1a10b043c5160282aa2a404433cf9873adfaa850412d883d40903b44733e5c5415a3f44bfa5308ccae1c2f6578c09264
|
7
|
+
data.tar.gz: ea88fe2e2a0da27ed8967ad2d08de4e775afd5e1233516e65b81fe91b743a4f8a558ff06ae1dd5994b73dfa97cdfc5c08c4107e46693ca932854b1b0712a9190
|
data/Gemfile.lock
CHANGED
data/lib/settings.rb
CHANGED
@@ -12,7 +12,7 @@ module UNotifier
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.
|
15
|
+
def self.filter_user_customizable(config)
|
16
16
|
customizable = config.map do |key, subkeys|
|
17
17
|
filtered =
|
18
18
|
subkeys
|
@@ -33,14 +33,37 @@ module UNotifier
|
|
33
33
|
customizable.to_h.reject { |_, subkeys| subkeys.empty? }
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.filter_system_customizable(config)
|
37
|
+
customizable = config.map do |key, subkeys|
|
38
|
+
filtered =
|
39
|
+
subkeys
|
40
|
+
.select { |_, value| value.key?("system") }
|
41
|
+
.map { |subkey, value| [subkey, value["system"]] }
|
42
|
+
.select { |_, value| value["urgency"] == "regular" }
|
43
|
+
.each_with_object({}) do |(subkey, value), out|
|
44
|
+
out[subkey] = value["urgency"]
|
45
|
+
end
|
46
|
+
|
47
|
+
[key, filtered]
|
48
|
+
end
|
49
|
+
|
50
|
+
customizable.to_h.reject { |_, subkeys| subkeys.empty? }
|
51
|
+
end
|
52
|
+
|
36
53
|
def self.keys_from(config)
|
37
|
-
|
54
|
+
{
|
55
|
+
"user" => flatten_keys(filter_user_customizable(config)),
|
56
|
+
"system" => flatten_keys(filter_system_customizable(config)),
|
57
|
+
}
|
38
58
|
end
|
39
59
|
|
40
60
|
def self.grouped_by_urgency_keys_from(config)
|
41
|
-
keys_from(config).each_with_object({}) do |(
|
42
|
-
|
43
|
-
|
61
|
+
keys_from(config).each_with_object({}) do |(channel, keys), obj|
|
62
|
+
obj[channel] =
|
63
|
+
keys.each_with_object({}) do |(key, urgency), out|
|
64
|
+
out[urgency] ||= []
|
65
|
+
out[urgency] << key
|
66
|
+
end
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
data/lib/unotifier.rb
CHANGED
@@ -110,10 +110,15 @@ module UNotifier
|
|
110
110
|
user_settings = target.notification_settings
|
111
111
|
Settings
|
112
112
|
.grouped_by_urgency_keys_from(notifications_config)
|
113
|
-
.each_with_object({}) do |(
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
.each_with_object({}) do |(level, grouped_keys), obj|
|
114
|
+
obj[level] =
|
115
|
+
grouped_keys.each_with_object({}) do |(urgency, keys), settings|
|
116
|
+
settings[urgency] = keys.each_with_object({}) do |(key, _), out|
|
117
|
+
out[key] =
|
118
|
+
user_settings.is_a?(Hash) && user_settings.dig(level, key) ||
|
119
|
+
Settings::DEFAULT_URGENCY
|
120
|
+
end
|
121
|
+
end
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
@@ -8,6 +8,14 @@ module UNotifier
|
|
8
8
|
# Raise only when we're sure that config has "system" block
|
9
9
|
raise AttributeMissingError.new(key, "system") unless params
|
10
10
|
|
11
|
+
if config["system"]["urgency"] == "regular"
|
12
|
+
# Don't notify if user disabled the notification in settings
|
13
|
+
user_settings =
|
14
|
+
notification.target.notification_settings.is_a?(Hash) &&
|
15
|
+
notification.target.notification_settings.dig("system", notification.key)
|
16
|
+
return if user_settings == "off"
|
17
|
+
end
|
18
|
+
|
11
19
|
data = config["system"]["keys"].each_with_object({}) do |(head, attributes), obj|
|
12
20
|
head = head.to_sym
|
13
21
|
attributes = attributes.map(&:to_sym)
|
@@ -2,7 +2,10 @@ module UNotifier
|
|
2
2
|
module UserNotifier
|
3
3
|
def self.notify_user(notification, params = {})
|
4
4
|
locale_key = UNotifier.locale_key_for(notification.key, params)
|
5
|
-
|
5
|
+
|
6
|
+
user_settings =
|
7
|
+
notification.target.notification_settings.is_a?(Hash) &&
|
8
|
+
notification.target.notification_settings.dig("user", notification.key)
|
6
9
|
user_settings ||= Settings::DEFAULT_URGENCY
|
7
10
|
|
8
11
|
notify_with = []
|
data/lib/unotifier/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mgpnd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,11 +97,7 @@ dependencies:
|
|
97
97
|
description:
|
98
98
|
email:
|
99
99
|
- stillintop@gmail.com
|
100
|
-
executables:
|
101
|
-
- console
|
102
|
-
- rake
|
103
|
-
- rspec
|
104
|
-
- setup
|
100
|
+
executables: []
|
105
101
|
extensions: []
|
106
102
|
extra_rdoc_files: []
|
107
103
|
files:
|
@@ -112,10 +108,6 @@ files:
|
|
112
108
|
- LICENSE.txt
|
113
109
|
- README.md
|
114
110
|
- Rakefile
|
115
|
-
- bin/console
|
116
|
-
- bin/rake
|
117
|
-
- bin/rspec
|
118
|
-
- bin/setup
|
119
111
|
- lib/configuration.rb
|
120
112
|
- lib/exceptions.rb
|
121
113
|
- lib/hash.rb
|
data/bin/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "unotifier"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
require "pry"
|
10
|
-
Pry.start(__FILE__)
|
data/bin/rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rake' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rspec' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rspec-core", "rspec")
|