nrser-notify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f8af4ec1d9676f261753ee852e09e94ae51e1ee
4
+ data.tar.gz: b1ca0c4d98d885846937897f007dc48d8a6633d9
5
+ SHA512:
6
+ metadata.gz: cd1a2cdac6f40766d5bbdda8ceaedc2eee3d206d50c5f50091fb87f82ba580407251706420a62ba34163fcf413b6c876ecbf1f5de340f89934868ba6b1dd6fa9
7
+ data.tar.gz: a581d959136719b702babfaf0002d64613b910a5056b202003f9e6d74b0c23cd4a81e035d34afc082a5232039c07ea1e549151bc79f6a7a8f38ea9704bce62d2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 nrser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ nrser.rb-notify
2
+ ================================================================================
3
+
4
+ TODO project description.
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,183 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+
5
+ # Requirements
6
+ # ========================================================================
7
+
8
+ # Project / Package
9
+ # ------------------------------------------------------------------------
10
+
11
+ # Need {NRSER::Log::Plugin}
12
+ require 'nrser/log/plugin'
13
+
14
+
15
+ # Refinements
16
+ # =======================================================================
17
+
18
+
19
+ # Namespace
20
+ # =======================================================================
21
+
22
+ module NRSER
23
+ module Log
24
+ module Plugins
25
+
26
+
27
+ # Definitions
28
+ # =======================================================================
29
+
30
+ #
31
+ #
32
+ class Notify < NRSER::Log::Plugin
33
+
34
+ @method_name = :notify
35
+
36
+
37
+ # Attributes
38
+ # ========================================================================
39
+
40
+ # @return [#to_s]
41
+ # The `:activate` option value.
42
+ attr_reader :activate
43
+
44
+
45
+ # @return [#to_s]
46
+ # The `:open` option value.
47
+ attr_reader :open
48
+
49
+
50
+ # @return [#to_s]
51
+ # The `:execute` option value.
52
+ attr_reader :execute
53
+
54
+
55
+ # @return [#to_s]
56
+ # The `:sender` option value.
57
+ attr_reader :sender
58
+
59
+
60
+ # @return [#to_s]
61
+ # The `:sound` option value.
62
+ attr_reader :sound
63
+
64
+
65
+ # Construction
66
+ # ========================================================================
67
+
68
+ def initialize logger,
69
+ title: nil,
70
+ subtitle: nil,
71
+ group: nil,
72
+ activate: nil,
73
+ open: nil,
74
+ execute: nil,
75
+ sender: nil,
76
+ sound: nil,
77
+ icon: nil
78
+ super logger
79
+ @title = title
80
+ @subtitle = subtitle
81
+ @group = group
82
+ @activate = activate
83
+ @open = open
84
+ @execute = execute
85
+ @sender = sender
86
+ @sound = sound
87
+ @icon = icon
88
+ end
89
+
90
+
91
+ # Instance Methods
92
+ # ========================================================================
93
+
94
+ def title level
95
+ @title || "#{ level.to_s.upcase } - #{ logger.name }"
96
+ end
97
+
98
+
99
+ def subtitle
100
+ @subtitle
101
+ end
102
+
103
+
104
+ def icon level
105
+ @icon || NRSER::Notify::ROOT / 'assets' / 'notify' / "#{ level }.png"
106
+ end
107
+
108
+
109
+ def group
110
+ return @group unless @group.nil?
111
+
112
+ if SemanticLogger.application != 'Semantic Logger'
113
+ return SemanticLogger.application
114
+ end
115
+
116
+ $0 # or Process.pid ?
117
+ end
118
+
119
+
120
+ # Get the options for {NRSER::Notify.notify} for a log call.
121
+ #
122
+ # @note
123
+ # Right now, {NRSER::Notify.notify} only supports [terminal-notifier][]
124
+ # as a backend, and passes the options directly, so these are really the
125
+ # options for {TerminalNotifier.notify}.
126
+ #
127
+ # @return [Hash<Symbol, String>]
128
+ #
129
+ def options level:, message:, payload:, exception:
130
+ {
131
+ title: title( level ),
132
+ subtitle: subtitle,
133
+ group: group,
134
+ activate: activate,
135
+ open: open,
136
+ execute: execute,
137
+ sender: sender,
138
+ sound: sound,
139
+ appIcon: icon( level ),
140
+ }.compact.transform_values &:to_s
141
+ end
142
+
143
+
144
+ # Handle a log call. Calls `super`, and if that indicates that the log was
145
+ # sent then dispatches the notification¹.
146
+ #
147
+ # > ¹ Except for `trace` level log messages - we never notify of those.
148
+ #
149
+ # @param (see NRSER::Log::Plugin#call)
150
+ #
151
+ # @return [Boolean]
152
+ # `true` if the log was sent (met level and not filtered).
153
+ #
154
+ # def call level, message = nil, payload = nil, exception = nil, &block
155
+ def call level:, message:, payload:, exception:, metric:, &block
156
+ super.tap { |was_logged|
157
+ # TODO Doesn't seem the return value *totally* represents if the log was
158
+ # sent or not... there's some additional logic?
159
+ #
160
+ # Also, we never notify for `trace` log messages regardless of log level.
161
+ #
162
+ if level != :trace && was_logged
163
+ NRSER::Notify.notify \
164
+ message,
165
+ **options(
166
+ level: level,
167
+ message: message,
168
+ payload: payload,
169
+ exception: exception,
170
+ )
171
+ end
172
+ }
173
+ end # #call
174
+
175
+ end # class Notify
176
+
177
+
178
+ # /Namespace
179
+ # =======================================================================
180
+
181
+ end # module Plugins
182
+ end # module Log
183
+ end # module NRSER
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'nrser/notify'
5
+ require 'nrser/log/plugins/notify'
6
+ NRSER::Log::Logger.plugin NRSER::Log::Plugins::Notify
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ require 'pathname'
11
+
12
+
13
+ # Namespace
14
+ # =======================================================================
15
+
16
+ module NRSER
17
+
18
+
19
+ # Definitions
20
+ # =======================================================================
21
+
22
+ module Notify
23
+
24
+ # Absolute, expanded path to the gem's root directory.
25
+ #
26
+ # Here in `//lib/nrser/version` so that it can be used via
27
+ #
28
+ # require 'nrser/version'
29
+ #
30
+ # without loading the entire module.
31
+ #
32
+ # @return [Pathname]
33
+ #
34
+ ROOT = (
35
+ Pathname.new( __FILE__ ).dirname / '..' / '..' / '..'
36
+ ).expand_path
37
+
38
+
39
+ # String version of the gem.
40
+ #
41
+ # @return [String]
42
+ #
43
+ VERSION = (ROOT / 'VERSION').read
44
+
45
+ end
46
+
47
+
48
+ # /Namespace
49
+ # =======================================================================
50
+
51
+ end # module NRSER
@@ -0,0 +1,95 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ # Deps
11
+ # -----------------------------------------------------------------------
12
+
13
+ # Need {NRSER::Log}, etc.
14
+ require 'nrser'
15
+
16
+ # Need {NRSER::LazyAttr} decorator.
17
+ require 'nrser/meta/lazy_attr'
18
+
19
+ require 'terminal-notifier'
20
+
21
+ # Project / Package
22
+ # -----------------------------------------------------------------------
23
+
24
+ require_relative './notify/version'
25
+
26
+
27
+ # Namespace
28
+ # =======================================================================
29
+
30
+ module NRSER
31
+
32
+
33
+ # Definitions
34
+ # =======================================================================
35
+
36
+ module Notify
37
+
38
+ +NRSER::LazyAttr
39
+ # Is the `terminal-notifier` gem available?
40
+ #
41
+ # [terminal-notifier][] is not an NRSER dependency since it does not make
42
+ # sense for many systems and situations. It must be installed separately.
43
+ #
44
+ # [terminal-notifier]: https://rubygems.org/gems/terminal-notifier
45
+ #
46
+ # Tests by trying to `require` it.
47
+ #
48
+ # @return [Boolean]
49
+ #
50
+ def self.terminal_notifier?
51
+ begin
52
+ require 'terminal-notifier'
53
+ rescue LoadError => error
54
+ false
55
+ else
56
+ TerminalNotifier.available?
57
+ end
58
+ end # .terminal_notifier?
59
+
60
+
61
+ +NRSER::LazyAttr
62
+ # Can we send notification to the user?
63
+ #
64
+ # Right now, only {.terminal_notifier?} is tested, but we can add more
65
+ # options in the future.
66
+ #
67
+ # @return [Boolean]
68
+ #
69
+ def self.available?
70
+ terminal_notifier?
71
+ end # .available?
72
+
73
+
74
+ # Send a notification to the use *if* notifications are {.available?}.
75
+ #
76
+ def self.notify message, **options, &block
77
+ return false unless available?
78
+ notify! message, **options, &block
79
+ end
80
+
81
+
82
+ # Force sending of a notification regardless of {.available?}.
83
+ #
84
+ def self.notify! message, **options, &block
85
+ require 'terminal-notifier'
86
+ TerminalNotifier.notify message, **options, &block
87
+ end
88
+
89
+ end
90
+
91
+
92
+ # /Namespace
93
+ # =======================================================================
94
+
95
+ end # module NRSER
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nrser-notify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nrser
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.16.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.16'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.16.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '12.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: yard
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.12
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.9.12
75
+ - !ruby/object:Gem::Dependency
76
+ name: github-markup
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.6'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.6'
89
+ - !ruby/object:Gem::Dependency
90
+ name: yard-commonmarker
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.3.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.3.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: pry
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.10.4
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.10.4
117
+ - !ruby/object:Gem::Dependency
118
+ name: nrser
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.3.6
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.3.6
131
+ - !ruby/object:Gem::Dependency
132
+ name: terminal-notifier
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 2.0.0
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 2.0.0
145
+ description:
146
+ email:
147
+ - neil@neilsouza.com
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - LICENSE.txt
153
+ - README.md
154
+ - assets/notify/debug.png
155
+ - assets/notify/error.png
156
+ - assets/notify/info.png
157
+ - assets/notify/warn.png
158
+ - lib/nrser/log/plugins/notify.rb
159
+ - lib/nrser/notify.rb
160
+ - lib/nrser/notify/setup.rb
161
+ - lib/nrser/notify/version.rb
162
+ homepage: https://github.com/nrser/nrser.rb-notify
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.5.2.2
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: User notification support (OSX-only for now)
186
+ test_files: []