sound_notifier 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6405e91988be70057056ccc82d5de11eb9ec3bb
4
+ data.tar.gz: 2c9c281081d337d16259d046e723923a932cd7cb
5
+ SHA512:
6
+ metadata.gz: 4bd41458ccc034c818c81c1a2b920a8829143523f576f6be31e40e9883d8eaceb155c212de82e999dbb75df84ebb397f43f6f9d5320a89393a48bfc4ed23b2ec
7
+ data.tar.gz: de84bbffff4a8245dab02eaf2aaf61e4215fc2d807c44675bcb765d4a96ad864108cd461e8d4d749a69966a1a5625783d781d549c6c406544518156e85c3418a
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ .dat*
13
+ .repl_history
14
+ build/
15
+ /.yardoc/
16
+ /_yardoc/
17
+ /doc/
18
+ /rdoc/
19
+ /.bundle/
20
+ /vendor/bundle
21
+ /lib/bundler/man/
22
+ Gemfile.lock
23
+ .ruby-version
24
+ .ruby-gemset
25
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sound_notifier.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Anatolii Didukh
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # SoundNotifier
2
+ Sound notification library for guard
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ group :development do
10
+ ...
11
+ gem 'notifanny', github: 'railsme/notiffany'
12
+ gem 'sound_notifier'
13
+ ...
14
+ end
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ ## Usage
22
+
23
+ Add to your Guardfile:
24
+ ```
25
+ notification :sound
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/railsme/sound_notifier.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sound_notifier"
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
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
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
Binary file
Binary file
Binary file
@@ -0,0 +1,94 @@
1
+ # SoundNotifier library for notiffany
2
+ class SoundNotifier
3
+ DATA_PATH = File.expand_path('../../data', __FILE__)
4
+ VERSION = '0.1.2'.freeze
5
+
6
+ # UnsupportedPlatform exception
7
+ class UnsupportedPlatform < RuntimeError
8
+ def initialize
9
+ super
10
+ @reason = %(Unsupported platform #{RbConfig::CONFIG['host_os'].inspect})
11
+ end
12
+
13
+ def message
14
+ @reason
15
+ end
16
+ end
17
+
18
+ attr_reader :type
19
+
20
+ class << self
21
+ def execute(type = :notify)
22
+ new(type).notify
23
+ end
24
+ end
25
+
26
+ def initialize(type)
27
+ @type = type
28
+ check_host_supported
29
+ end
30
+
31
+ def kernel
32
+ @kernel ||= Kernel
33
+ end
34
+
35
+ def notify
36
+ return unless File.exist?(sound_file) && play_command
37
+ @sound_thread = Thread.new { play_file }
38
+ end
39
+
40
+ private
41
+
42
+ def supported_hosts
43
+ %w(darwin linux)
44
+ end
45
+
46
+ def notification_type
47
+ [:failed, :notify, :success].include?(type) ? type : :notify
48
+ end
49
+
50
+ def check_host_supported
51
+ expr = /#{supported_hosts * '|'}/
52
+ raise UnsupportedPlatform unless expr.match(RbConfig::CONFIG['host_os'])
53
+ end
54
+
55
+ def platform
56
+ @platform ||= RUBY_PLATFORM
57
+ end
58
+
59
+ def osx?
60
+ platform.downcase.include?('darwin')
61
+ end
62
+
63
+ def linux?
64
+ platform.downcase.include?('linux')
65
+ end
66
+
67
+ def sound_file
68
+ File.join(DATA_PATH, %(#{notification_type}.mp3))
69
+ end
70
+
71
+ def play_file
72
+ th = Thread.current
73
+ th['pid'] = kernel.spawn(play_command)
74
+ Process.wait(th['pid'])
75
+ ensure
76
+ th.kill
77
+ end
78
+
79
+ def play_command
80
+ if osx?
81
+ %(afplay #{sound_file})
82
+ elsif linux? && linux_player
83
+ %(#{linux_player} #{sound_file} &>/dev/null)
84
+ end
85
+ end
86
+
87
+ def linux_player
88
+ %w(mpg321 mpg123).find do |player|
89
+ kernel.system(
90
+ %(which #{player} &>/dev/null && type #{player} &>/dev/null)
91
+ )
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sound_notifier'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sound_notifier'
8
+ spec.version = SoundNotifier::VERSION
9
+ spec.authors = ['Anatolii Didukh']
10
+ spec.email = ['railsme7@gmail.com']
11
+
12
+ spec.summary = %(Sound notification for guard.)
13
+ spec.description = %(Sound notifications library for guard)
14
+ spec.homepage = %(https://github.com/railsme/sound_notifier)
15
+
16
+ spec.files =
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.11'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sound_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Anatolii Didukh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-24 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Sound notifications library for guard
56
+ email:
57
+ - railsme7@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - data/failed.mp3
72
+ - data/notify.mp3
73
+ - data/success.mp3
74
+ - lib/sound_notifier.rb
75
+ - sound_notifier.gemspec
76
+ homepage: https://github.com/railsme/sound_notifier
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Sound notification for guard.
99
+ test_files: []