unotifier 0.1.1 → 0.2.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: 9c47b889fda3eebd43870746eec2eaf08e17c5deb8f0fd33088526bd3cda9c30
4
- data.tar.gz: e879c1e1a6ee421a493b6fb27bbe6f6b1575553fd5f4eac2f8af707caa0af228
3
+ metadata.gz: ab124f207e21102d80111f02fca618367788bb09e0c3a4565fd9aa74087253e7
4
+ data.tar.gz: 06b4f14f4252785d1e41a1d79ed754f7c939d6449f33717343f1b1515ee5be99
5
5
  SHA512:
6
- metadata.gz: 2f46b3e1bf12f9f72d4514c7f16f74343872539f2b33d8dd2b16836fc21e7232a9bf63724c53ec8c05d0dcd0043613bf6f04dccbc0eb92bab3eff9acf1ee8548
7
- data.tar.gz: 41d3b96af73fb7747876b8cdfb5770c996404535f9c0449a40587063b6ac68086f4eaf858be05a8ed64c3cd54493645f9a86b7ba77919ba135006e1cbc8a335c
6
+ metadata.gz: a441acebc93d75306f68dc241184891d17908c6737c535a2c18f089885814d9ccedc40db76319c0ab7d1e854f2f70e100bff1be9e3a5fe73bf147d91cd3d8d73
7
+ data.tar.gz: '094405411bf9a32bfde02c00de440c1ffff31c2d051c76c5404688a6395a00f646a613623633a4737573ed8c0e1ab2d7ef52f7d08e6ed46638009d7bf37bf297'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unotifier (0.1.1)
4
+ unotifier (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/configuration.rb CHANGED
@@ -4,12 +4,14 @@ module UNotifier
4
4
  attr_accessor :external_providers
5
5
  attr_accessor :resource_class
6
6
  attr_accessor :notifications_path
7
+ attr_accessor :localization_provider
7
8
 
8
9
  def initialize
9
10
  @site_providers = []
10
11
  @external_providers = []
11
12
  @resource_class = nil
12
13
  @notifications_path = nil
14
+ @localization_provider = nil
13
15
  end
14
16
  end
15
17
  end
@@ -26,6 +26,7 @@ module UNotifier
26
26
  autohide_delay: notification.autohide_delay || @autohide_delay,
27
27
  user_login: notification.target.login,
28
28
  link: notification.link,
29
+ urgency: notification.urgency,
29
30
  }
30
31
  end
31
32
  end
data/lib/settings.rb ADDED
@@ -0,0 +1,28 @@
1
+ module UNotifier
2
+ class Settings
3
+ def self.customizable?(config)
4
+ %w(regular optional).include?(config["urgency"])
5
+ end
6
+
7
+ def self.filter_customizable(config)
8
+ config.map do |key, subkeys|
9
+ filtered = subkeys.select do |subkey, value|
10
+ (value.has_key?("urgency") && customizable?(value)) ||
11
+ (value.has_key?("target") && value["target"].values.any? { |subvalue| customizable?(subvalue) })
12
+ end
13
+
14
+ [key, filtered.keys]
15
+ end.to_h.select { |_, subkeys| subkeys.any? }
16
+ end
17
+
18
+ def self.keys_from(config)
19
+ flatten_keys filter_customizable(config)
20
+ end
21
+
22
+ private
23
+
24
+ def self.flatten_keys(keys)
25
+ keys.map { |key, subkeys| subkeys.map { |s| "#{key}.#{s}" } }.flatten
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module UNotifier
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/unotifier.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require "yaml"
2
- require "i18n"
3
2
 
4
3
  require_relative "unotifier/version"
5
4
  require_relative "exceptions"
6
5
  require_relative "provider"
7
6
  require_relative "configuration"
7
+ require_relative "settings"
8
8
 
9
9
  module UNotifier
10
10
  class << self
@@ -21,7 +21,7 @@ module UNotifier
21
21
 
22
22
  def self.notifications_config
23
23
  @notifications_config ||= YAML.load_file(configuration.notifications_path)
24
- rescue Errno::ENOENT => e
24
+ rescue Errno::ENOENT
25
25
  raise NotificationsConfigNotFoundError.new(configuration.notifications_path)
26
26
  end
27
27
 
@@ -74,9 +74,11 @@ module UNotifier
74
74
 
75
75
  notification = configuration.resource_class.new(
76
76
  key: key,
77
- title: I18n.t("#{locale_key}.title", params.merge(locale: target.locale, default: "")),
78
- body: I18n.t("#{locale_key}.title", params.merge(locale: target.locale, default: "")),
77
+ target: target,
78
+ title: configuration.localization_provider.t("#{locale_key}.title", params.merge(locale: target.locale, default: "")),
79
+ body: configuration.localization_provider.t("#{locale_key}.title", params.merge(locale: target.locale, default: "")),
79
80
  link: params[:link],
81
+ autohide_delay: params[:autohide_delay],
80
82
  urgency: urgency
81
83
  )
82
84
  notification.save!
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Rashev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,7 @@ files:
120
120
  - lib/provider.rb
121
121
  - lib/provider/action_cable.rb
122
122
  - lib/provider/action_mailer.rb
123
+ - lib/settings.rb
123
124
  - lib/unotifier.rb
124
125
  - lib/unotifier/version.rb
125
126
  - unotifier.gemspec