notifier 1.0.0 → 1.2.2

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: 4e8f22ae020099416927c4342232f8e37631292454b51036ee75a80227da2152
4
- data.tar.gz: bed78ad310c8577665578bc763e1e3f20f100e368d66c9f13fd460b38486bb2a
3
+ metadata.gz: 8372bdfe560b7af14829350fbf06a4eec6efa573f6b87fe992dab61cc1dd74cd
4
+ data.tar.gz: bb4ebe4172bcea05940571909984b82d1e64eb146068ccffb00a6c028fe1313e
5
5
  SHA512:
6
- metadata.gz: 2bca083c02fb0ee73772a8f3604ca2749b6e9cee6e6f75bff623afc948b0032aee87af722b3e071391731043749a0f1d9470b472c23f405e719b78df62183b9c
7
- data.tar.gz: a082e4f102062da75d76e21253848bf1cf56a08780a3fac4c7f2e032310e5c9c45cf7005700e84ce7d336632aa7b7ace9dd8c5493196074350c4bc6fa9dfb79e
6
+ metadata.gz: f37a5e1fe74a4308edc897948c6450c272a4498a4a2abcf378133e1d8741235274b589809f77286eccfa28f1afce555ff36a4b33d33b3083ea42eedb587c0667
7
+ data.tar.gz: 8f67cf67140471f8621088032eda74d715150777482ad1afdfd5585949b473911e8a33c9ca87885576b4c05c910921832e2eced3bb371c25466eec1b260f846e
data/README.md CHANGED
@@ -7,7 +7,6 @@ Send system notifications on several platforms with a simple and unified API.
7
7
  Currently supports:
8
8
 
9
9
  - terminal-notifier (Notification Center wrapper for Mac OS X)
10
- - GNTP Protocol (Growl, with Vagrant support)
11
10
  - Kdialog (Linux/KDE)
12
11
  - Knotify (Linux/KDE)
13
12
  - OSD Cat (Linux)
@@ -68,6 +67,14 @@ prefer:
68
67
  Notifier.default_notifier = :notify_send
69
68
  ```
70
69
 
70
+ Alternatively, you can set the default notifier by using the `NOTIFIER` env var.
71
+ The following example assumes `test_notifier` is configured on this Rails
72
+ project. The env var has precedence of `Notifier.default_notifier`.
73
+
74
+ ```console
75
+ $ NOTIFIER=hud rails test
76
+ ```
77
+
71
78
  The available names are `terminal_notifier`, `kdialog`, `knotify`,
72
79
  `notify_send`, `osd_cat`, and `snarl`.
73
80
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Notifier
4
+ module Hud
5
+ extend self
6
+
7
+ def supported?
8
+ Notifier.os?(/darwin/) && hud_bin
9
+ end
10
+
11
+ def hud_bin
12
+ @hud_bin ||= [
13
+ "/Applications/hud.app/Contents/MacOS/cli",
14
+ "~/Applications/hud.app/Contents/MacOS/cli"
15
+ ].first {|path| File.expand_path(path) }
16
+ end
17
+
18
+ def notify(options)
19
+ command = [
20
+ hud_bin,
21
+ "--title",
22
+ options[:title].to_s,
23
+ "--message",
24
+ options[:message].to_s,
25
+ "--symbol-name",
26
+ options[:image].to_s
27
+ ]
28
+
29
+ Thread.new { system(*command) }.join
30
+ end
31
+ end
32
+ end
@@ -12,9 +12,17 @@ module Notifier
12
12
 
13
13
  def notify(options)
14
14
  command = [
15
- "dcop", "knotify", "default", "notify", "eventname",
16
- options[:title].to_s, options[:message].to_s,
17
- "", "", "16", "2"
15
+ "dcop",
16
+ "knotify",
17
+ "default",
18
+ "notify",
19
+ "eventname",
20
+ options[:title].to_s,
21
+ options[:message].to_s,
22
+ "",
23
+ "",
24
+ "16",
25
+ "2"
18
26
  ]
19
27
 
20
28
  Thread.new { system(*command) }.join
@@ -3,8 +3,8 @@
3
3
  module Notifier
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 0
7
- PATCH = 0
6
+ MINOR = 2
7
+ PATCH = 2
8
8
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
9
9
  end
10
10
  end
data/lib/notifier.rb CHANGED
@@ -6,9 +6,11 @@ require "digest/md5"
6
6
  require "timeout"
7
7
  require "rbconfig"
8
8
  require "English"
9
+ require "net/http"
9
10
 
10
11
  module Notifier
11
12
  require "notifier/snarl"
13
+ require "notifier/hud"
12
14
  require "notifier/osd_cat"
13
15
  require "notifier/knotify"
14
16
  require "notifier/kdialog"
@@ -28,7 +30,8 @@ module Notifier
28
30
  end
29
31
 
30
32
  def notifier
31
- supported_notifier_from_name(default_notifier) || supported_notifiers.first
33
+ supported_notifier_from_name(ENV.fetch("NOTIFIER", default_notifier)) ||
34
+ supported_notifiers.first
32
35
  end
33
36
 
34
37
  def notify(options)
@@ -36,9 +39,11 @@ module Notifier
36
39
  end
37
40
 
38
41
  def notifiers
39
- constants.filter_map do |name|
42
+ notifiers = constants.filter_map do |name|
40
43
  const_get(name) unless skip_constants.include?(name.to_s)
41
- end + [Placebo]
44
+ end
45
+
46
+ notifiers.sort_by(&:name) + [Placebo]
42
47
  end
43
48
 
44
49
  def supported_notifiers
data/notifier.gemspec CHANGED
@@ -32,4 +32,5 @@ Gem::Specification.new do |s|
32
32
  s.add_development_dependency "rubocop"
33
33
  s.add_development_dependency "rubocop-fnando"
34
34
  s.add_development_dependency "simplecov"
35
+ s.add_development_dependency "test_notifier"
35
36
  end
@@ -11,6 +11,11 @@ class NotifierTest < Minitest::Test
11
11
  end
12
12
 
13
13
  Notifier.default_notifier = nil
14
+ ENV.delete("NOTIFIER")
15
+ end
16
+
17
+ teardown do
18
+ Notifier.default_notifier = :hud
14
19
  end
15
20
 
16
21
  test "retrieves list of supported notifiers" do
@@ -23,8 +28,9 @@ class NotifierTest < Minitest::Test
23
28
  test "returns first available notifier" do
24
29
  Notifier::Snarl.stubs(:supported?).returns(true)
25
30
  Notifier::Knotify.stubs(:supported?).returns(true)
31
+ Notifier::Hud.stubs(:supported?).returns(true)
26
32
 
27
- assert_equal Notifier::Snarl, Notifier.notifier
33
+ assert_equal Notifier::Hud, Notifier.notifier
28
34
  end
29
35
 
30
36
  test "prefers default notifier" do
@@ -36,6 +42,17 @@ class NotifierTest < Minitest::Test
36
42
  assert_equal Notifier::Knotify, Notifier.notifier
37
43
  end
38
44
 
45
+ test "prefers default notifier using env var" do
46
+ ENV["NOTIFIER"] = "knotify"
47
+
48
+ Notifier::Snarl.stubs(:supported?).returns(true)
49
+ Notifier::Knotify.stubs(:supported?).returns(true)
50
+
51
+ Notifier.default_notifier = :snarl
52
+
53
+ assert_equal Notifier::Knotify, Notifier.notifier
54
+ end
55
+
39
56
  test "sends notification" do
40
57
  params = {
41
58
  title: "Some title",
@@ -50,7 +67,7 @@ class NotifierTest < Minitest::Test
50
67
  end
51
68
 
52
69
  test "retrieves list of all notifiers" do
53
- assert_equal 7, Notifier.notifiers.size
70
+ assert_equal 8, Notifier.notifiers.size
54
71
  end
55
72
 
56
73
  test "considers Placebo as fallback notifier" do
@@ -60,6 +77,7 @@ class NotifierTest < Minitest::Test
60
77
  test "returns notifier by its name" do
61
78
  assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
62
79
  assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
80
+ assert_equal Notifier::Hud, Notifier.from_name(:hud)
63
81
  end
64
82
 
65
83
  test "returns notifier by its name when supported" do
data/test/test_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ENV.delete("NOTIFIER")
4
+
3
5
  require "simplecov"
4
6
  SimpleCov.start
5
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-20 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-utils
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test_notifier
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Send system notifications on several platforms with a simple and unified
98
112
  API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
99
113
  email:
@@ -109,6 +123,7 @@ files:
109
123
  - README.md
110
124
  - Rakefile
111
125
  - lib/notifier.rb
126
+ - lib/notifier/hud.rb
112
127
  - lib/notifier/kdialog.rb
113
128
  - lib/notifier/knotify.rb
114
129
  - lib/notifier/notify_send.rb
@@ -118,8 +133,8 @@ files:
118
133
  - lib/notifier/terminal_notifier.rb
119
134
  - lib/notifier/version.rb
120
135
  - notifier.gemspec
121
- - test/notifier/notifier_test.rb
122
136
  - test/notifier/snarl_test.rb
137
+ - test/notifier_test.rb
123
138
  - test/test_helper.rb
124
139
  homepage: http://rubygems.org/gems/notifier
125
140
  licenses: []
@@ -147,6 +162,6 @@ specification_version: 4
147
162
  summary: Send system notifications on several platforms with a simple and unified
148
163
  API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
149
164
  test_files:
150
- - test/notifier/notifier_test.rb
151
165
  - test/notifier/snarl_test.rb
166
+ - test/notifier_test.rb
152
167
  - test/test_helper.rb