notifies 0.1.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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDU5OGYwMWVkNGY0NjE2M2YxYTE0OGExNTgxZDE3NjU0OTc0OGUxNg==
5
+ data.tar.gz: !binary |-
6
+ OWM3M2EzY2RmMGU1ODFiMDdhMjI5OTUyMThlYjBlYmQ5ZWFkZmRjMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjQ0N2MxYjA2NTAzMTc4M2UyYjhmYzBjNTY3MThiZmZkMGE3MDczOTgxMzU3
10
+ NTA4NzAyMjZiMzIzOTEyMDk4ZDY3Y2U2NTQxMjViYTY2MzM4NWU1YWYyMDQ5
11
+ MjJiN2ExYzdhYzE0MzZlMDc3ZWJiYThlNjcyMzg5MGY0NGU4NzI=
12
+ data.tar.gz: !binary |-
13
+ MmFiN2ZjY2RjN2M3YjgxOGU3NjQ1NGRlYjg3ZjQ2M2FlOTFkMDU0YTNkNjEy
14
+ NWE2NzljMjAyZjJiMDU4YWEzNzljYjFjZjY1MTkzMDg2ODEwMzg4ODc2NjA1
15
+ N2IxMGI5YWIxNmE0MWViNWJlMzVhY2UxOWFkYmZkZmU3MTI0ZmI=
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'growl', '~> 1.0.3'
4
+ gem 'terminal-notifier-guard', '~> 1.5.3'
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem 'bundler'
10
+ gem 'rake'
11
+ gem 'rspec'
12
+ gem 'jeweler'
13
+ gem 'gem-release'
14
+ gem 'rake-version'
15
+ gem 'simplecov'
16
+ gem 'coveralls', require: false
17
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Simon Oulevay (Alpha Hydrae)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,76 @@
1
+ # notifies
2
+
3
+ **Simple notifications with Growl and OS X Notification Center.**
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/notifies.png)](http://badge.fury.io/rb/notifies)
6
+ [![Dependency Status](https://gemnasium.com/AlphaHydrae/notifies.png)](https://gemnasium.com/AlphaHydrae/notifies)
7
+ [![Build Status](https://secure.travis-ci.org/AlphaHydrae/notifies.png)](http://travis-ci.org/AlphaHydrae/notifies)
8
+ [![Coverage Status](https://coveralls.io/repos/AlphaHydrae/notifies/badge.png?branch=master)](https://coveralls.io/r/AlphaHydrae/notifies?branch=master)
9
+
10
+ ## Installation
11
+
12
+ In your Gemfile:
13
+
14
+ ```rb
15
+ gem 'notifies', '~> 0.1.0'
16
+ ```
17
+
18
+ Manually:
19
+
20
+ gem install notifies
21
+
22
+ ## Usage
23
+
24
+ It's as simple as:
25
+
26
+ ```rb
27
+ Notifies.notify 'Hello World!'
28
+ ```
29
+
30
+ This will automatically select and use the first available notifier.
31
+
32
+ The method returns:
33
+
34
+ * `true` if everything worked;
35
+ * `nil` if no notifier is available on your system;
36
+ * `false` if the notifier failed.
37
+
38
+ ### Notification Options
39
+
40
+ The following options are available:
41
+
42
+ * `:type` - The type of notification. With some notifiers this changes the icon.
43
+ This must be either `:ok`, `:info`, `:warning` or `:error`. By default, `:info` is selected.
44
+ * `:title` - The title of the notification. This is set by the notifier by default (e.g. "growlnotify" for the Growl notifier).
45
+ * `:subtitle` - An optional subtitle.
46
+ * `:icon` - Custom icon. Only supported with Growl, see [the documentation](https://github.com/visionmedia/growl#normaized-icons).
47
+
48
+ ```rb
49
+ Notifies.notify 'Hello World!', type: :ok, title: 'My App', subtitle: 'Notifications'
50
+ ```
51
+
52
+ ### Aliases
53
+
54
+ You can uses these aliases instead of passing the `:type` option:
55
+
56
+ ```rb
57
+ Notifies.notify_ok 'It works!'
58
+ Notifies.notify_info 'Useful information'
59
+ Notifies.notify_warning 'Beware'
60
+ Notifies.notify_error 'Broken'
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ * [Fork](https://help.github.com/articles/fork-a-repo)
66
+ * Create a topic branch - `git checkout -b my_branch`
67
+ * Push to your branch - `git push origin my_branch`
68
+ * Create a [pull request](http://help.github.com/pull-requests/) from your branch
69
+
70
+ Please add a changelog entry for new features and bug fixes.
71
+ Writing specs will get your code pulled faster.
72
+
73
+ ## Meta
74
+
75
+ * **Author:** Simon Oulevay (Alpha Hydrae)
76
+ * **License:** MIT (see [LICENSE.txt](https://raw.github.com/AlphaHydrae/notifies/master/LICENSE.txt))
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../lib/notifies')
3
+
4
+ # TODO: implement command line with commander
5
+ Notifies.notify ARGV.shift
@@ -0,0 +1,93 @@
1
+ # encoding: UTF-8
2
+
3
+ module Notifies
4
+ VERSION = '0.1.0'
5
+ NOTIFIERS = {}
6
+ @@enabled = true
7
+
8
+ class Error < StandardError; end
9
+ class UnknownNotifierError < Error
10
+
11
+ def initialize msg
12
+ super "Unknown notifier(s) #{msg}"
13
+ end
14
+ end
15
+
16
+ def self.notify msg, options = {}
17
+ return false if !@@enabled or (options.key?(:enabled) and !options[:enabled])
18
+ n = notifier options
19
+ n ? n.notify(msg, options) : nil
20
+ end
21
+
22
+ class << self
23
+ [ :ok, :info, :warning, :error ].each do |type|
24
+ define_method "notify_#{type}" do |*args|
25
+ options = args.last.kind_of?(Hash) ? args.last : {}.tap{ |h| args << h }
26
+ options[:type] = type
27
+ notify *args
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.notifier *args
33
+ options = args.last.kind_of?(Hash) ? args.pop : {}
34
+
35
+ if key = args.shift
36
+ raise UnknownNotifierError.new(key.inspect) unless n = NOTIFIERS[key]
37
+ return !options[:available] || n && n.available? ? n : nil
38
+ end
39
+
40
+ ordered_notifiers(options).each_pair do |key,notifier|
41
+ return notifier if notifier.available?
42
+ end
43
+
44
+ nil
45
+ end
46
+
47
+ def self.preferred
48
+ NOTIFIERS.keys
49
+ end
50
+
51
+ def self.prefer *keys
52
+ NOTIFIERS.replace(ordered_notifiers(preferred: keys.flatten)).keys
53
+ end
54
+
55
+ def self.enabled= enabled
56
+ @@enabled = !!enabled
57
+ end
58
+
59
+ def self.enabled?
60
+ @@enabled
61
+ end
62
+
63
+ def self.register key, notifier
64
+ # TODO: test key override
65
+ NOTIFIERS[key] = notifier
66
+ end
67
+
68
+ def self.register_defaults
69
+ register :notification_center, Notifies::NotificationCenter
70
+ register :growl, Notifies::Growl
71
+ end
72
+
73
+ private
74
+
75
+ def self.ordered_notifiers options = {}
76
+ return NOTIFIERS unless options[:preferred]
77
+
78
+ keys = [ options.delete(:preferred) ].flatten.uniq
79
+ unknown_keys = keys.reject{ |k| NOTIFIERS[k] }
80
+ raise UnknownNotifierError.new(unknown_keys.collect{ |k| k.inspect }.join(', ')) unless unknown_keys.empty?
81
+
82
+ notifiers = NOTIFIERS.dup
83
+
84
+ Hash.new.tap do |ordered|
85
+ keys.each{ |k| ordered[k] = notifiers.delete k }
86
+ notifiers.each_pair{ |k,v| ordered[k] = v }
87
+ end
88
+ end
89
+ end
90
+
91
+ Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
92
+
93
+ Notifies.register_defaults
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+ require 'growl'
3
+
4
+ module Notifies
5
+
6
+ class Growl
7
+
8
+ def self.available?
9
+ !!::Growl.installed?
10
+ end
11
+
12
+ def self.notify msg, options = {}
13
+ method = METHODS[options.delete(:type)] || :notify_info
14
+ ::Growl.send method, msg, growl_options(options)
15
+ end
16
+
17
+ private
18
+
19
+ METHODS = {
20
+ ok: :notify_ok,
21
+ info: :notify_info,
22
+ warning: :notify_warning,
23
+ error: :notify_error
24
+ }
25
+
26
+ def self.growl_options options = {}
27
+ Hash.new.tap do |h|
28
+ h[:name] = options[:title] if options[:title]
29
+ h[:title] = options[:subtitle] if options[:subtitle]
30
+ h[:icon] = options[:icon] if options[:icon]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+ require 'terminal-notifier-guard'
3
+
4
+ module Notifies
5
+
6
+ class NotificationCenter
7
+
8
+ def self.available?
9
+ !!TerminalNotifier::Guard.available?
10
+ end
11
+
12
+ def self.notify msg, options = {}
13
+ method = METHODS[options.delete(:type)] || :notify
14
+ TerminalNotifier::Guard.send method, msg, terminal_notifier_options(options)
15
+ end
16
+
17
+ private
18
+
19
+ METHODS = {
20
+ ok: :success,
21
+ info: :notify,
22
+ warning: :pending,
23
+ error: :failed
24
+ }
25
+
26
+ def self.terminal_notifier_options options = {}
27
+ Hash.new.tap do |h|
28
+ h[:title] = options[:title] if options[:title]
29
+ h[:subtitle] = options[:subtitle] if options[:subtitle]
30
+ end
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notifies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AlphaHydrae
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: growl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-notifier-guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: gem-release
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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake-version
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Ruby notifications with Growl and OS X Notification Center.
154
+ email: hydrae.alpha@gmail.com
155
+ executables:
156
+ - notifies
157
+ extensions: []
158
+ extra_rdoc_files:
159
+ - LICENSE.txt
160
+ - README.md
161
+ files:
162
+ - Gemfile
163
+ - LICENSE.txt
164
+ - README.md
165
+ - VERSION
166
+ - bin/notifies
167
+ - lib/notifies.rb
168
+ - lib/notifies/growl.rb
169
+ - lib/notifies/notification_center.rb
170
+ homepage: http://github.com/AlphaHydrae/notifies
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.1.5
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Simple notifications.
194
+ test_files: []