unotifier 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa686f0cd41483a94d0746b9538177adae345674774b7e7798cb507c9c2b61c
4
- data.tar.gz: 5e61daf30bfe7dbbdd62a0edb5f2cad5c2383e5ad3dc83482ad1cec0b61781c1
3
+ metadata.gz: 8a81b0764d3f887d08ea60520f2905dc87582adb3ac6c7dd80a5b9b1008fd3f1
4
+ data.tar.gz: 0e1172c73283881a6e8a08c3006e2c28a4686f4a20631df6c0d759fcecf8aa35
5
5
  SHA512:
6
- metadata.gz: 21fc2a10954d1a2c5e0fa1d6ae7eafc9ad199d02ec634b850c90393604669b5ee63e0d617985859507ed1eaf8787cbc1db227b7791e698308d8142d7b02d476a
7
- data.tar.gz: e96f359477dde1299d359a646b0efda3c40fba6a42c546e4dc1758e7df8bd39f663b4a89f5b61778678130ba9ba0d349ea1ccd430de22fceda4f317729b6a167
6
+ metadata.gz: 0023a587bb451a35ee378fb14e00c3ec1a10b043c5160282aa2a404433cf9873adfaa850412d883d40903b44733e5c5415a3f44bfa5308ccae1c2f6578c09264
7
+ data.tar.gz: ea88fe2e2a0da27ed8967ad2d08de4e775afd5e1233516e65b81fe91b743a4f8a558ff06ae1dd5994b73dfa97cdfc5c08c4107e46693ca932854b1b0712a9190
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unotifier (0.3.0)
4
+ unotifier (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,7 +12,7 @@ module UNotifier
12
12
  )
13
13
  end
14
14
 
15
- def self.filter_customizable(config)
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
- flatten_keys filter_customizable(config)
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 |(key, urgency), out|
42
- out[urgency] ||= []
43
- out[urgency] << key
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
 
@@ -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 |(urgency, keys), settings|
114
- settings[urgency] = keys.each_with_object({}) do |(key, _), out|
115
- out[key] = user_settings[key] || Settings::DEFAULT_URGENCY
116
- end
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
- user_settings = notification.target.notification_settings[notification.key]
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 = []
@@ -1,3 +1,3 @@
1
1
  module UNotifier
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  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.3.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-01-24 00:00:00.000000000 Z
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
@@ -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")
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here