libnotify 0.0.1 → 0.0.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.
- data/.gitignore +1 -0
- data/.watchr +21 -0
- data/README.rdoc +10 -5
- data/Rakefile +20 -2
- data/VERSION +1 -1
- data/lib/libnotify.rb +11 -13
- data/test/helper.rb +11 -0
- data/test/test_libnotify.rb +72 -0
- metadata +37 -4
data/.gitignore
CHANGED
data/.watchr
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
def run(*args)
|
3
|
+
system "ruby -rubygems -Ilib:test #{args.join(' ')}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def run_tests
|
7
|
+
system "rake test"
|
8
|
+
end
|
9
|
+
|
10
|
+
def underscore(file)
|
11
|
+
file.gsub('/', '_')
|
12
|
+
end
|
13
|
+
|
14
|
+
watch('test/test_.*\.rb') {|md| run md[0] }
|
15
|
+
watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" }
|
16
|
+
watch('test/helper.rb') { run_tests }
|
17
|
+
|
18
|
+
run_tests
|
19
|
+
|
20
|
+
Signal.trap("QUIT") { abort("\n") }
|
21
|
+
Signal.trap("INT") { run_tests }
|
data/README.rdoc
CHANGED
@@ -6,19 +6,24 @@ Ruby binding for libnotify using FFI.
|
|
6
6
|
|
7
7
|
require 'libnotify'
|
8
8
|
|
9
|
-
#
|
9
|
+
# Block syntax
|
10
10
|
Libnotify.new do |notify|
|
11
11
|
notify.summary = "world"
|
12
12
|
notify.body = "hello"
|
13
|
-
notify.timeout = 1.5 #
|
14
|
-
notify.urgency = :critical #
|
13
|
+
notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
|
14
|
+
notify.urgency = :critical # :low, :normal, :critical
|
15
15
|
notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
|
16
16
|
notify.show!
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
19
|
+
# Hash syntax
|
20
20
|
Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
|
21
21
|
|
22
|
+
# Mixed syntax
|
23
|
+
Libnotify.show(options) do |n|
|
24
|
+
n.timeout = 1.5 # overrides :timeout in options
|
25
|
+
end
|
26
|
+
|
22
27
|
== Install via gemcutter
|
23
28
|
gem install gemcutter
|
24
29
|
gem tumble
|
@@ -29,4 +34,4 @@ Ruby binding for libnotify using FFI.
|
|
29
34
|
|
30
35
|
== TODO
|
31
36
|
|
32
|
-
*
|
37
|
+
* Mock FFI calls
|
data/Rakefile
CHANGED
@@ -18,9 +18,11 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
|
19
19
|
gem.add_dependency "ffi"
|
20
20
|
|
21
|
-
|
21
|
+
gem.add_development_dependency "riot"
|
22
|
+
gem.add_development_dependency "riot_notifier"
|
23
|
+
gem.add_development_dependency "rr"
|
22
24
|
|
23
|
-
|
25
|
+
gem.test_files = Dir.glob('test/test_*.rb')
|
24
26
|
end
|
25
27
|
|
26
28
|
Jeweler::GemcutterTasks.new
|
@@ -31,8 +33,24 @@ Rake::TestTask.new(:test) do |test|
|
|
31
33
|
test.test_files = FileList.new('test/test_*.rb')
|
32
34
|
test.libs << 'test'
|
33
35
|
test.verbose = true
|
36
|
+
#test.warning = true
|
34
37
|
end
|
35
38
|
|
39
|
+
namespace :test do
|
40
|
+
desc "Run all tests on multiple ruby versions (requires rvm)"
|
41
|
+
task(:portability) do
|
42
|
+
%w(1.8.6 1.8.7 1.9.1 1.9.2 ree jruby).each do |version|
|
43
|
+
system <<-BASH
|
44
|
+
bash -c 'source ~/.rvm/scripts/rvm;
|
45
|
+
rvm #{version};
|
46
|
+
echo "--------- ruby #{version} ----------\n";
|
47
|
+
rake -s test'
|
48
|
+
BASH
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
36
54
|
# RDoc
|
37
55
|
Rake::RDocTask.new do |rd|
|
38
56
|
rd.title = "Riot Notifier"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/libnotify.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
1
|
require 'ffi'
|
5
2
|
|
6
3
|
module Libnotify
|
@@ -31,10 +28,11 @@ module Libnotify
|
|
31
28
|
|
32
29
|
class API
|
33
30
|
include FFI
|
34
|
-
|
31
|
+
attr_reader :timeout
|
32
|
+
attr_accessor :summary, :body, :icon_path, :urgency
|
35
33
|
|
36
34
|
def initialize(options = {}, &block)
|
37
|
-
self.summary = self.body = " "
|
35
|
+
self.summary = self.body = " " # Empty strings gives warnings...
|
38
36
|
self.urgency = :normal
|
39
37
|
self.timeout = nil
|
40
38
|
options.each { |key, value| send("#{key}=", value) if respond_to?(key) }
|
@@ -47,9 +45,9 @@ module Libnotify
|
|
47
45
|
|
48
46
|
def show!
|
49
47
|
notify_init(self.class.to_s) or raise "notify_init failed"
|
50
|
-
notify =
|
48
|
+
notify = notify_notification_new(summary, body, icon_path, nil)
|
51
49
|
notify_notification_set_urgency(notify, urgency)
|
52
|
-
notify_notification_set_timeout(notify, timeout)
|
50
|
+
notify_notification_set_timeout(notify, timeout || -1)
|
53
51
|
notify_notification_show(notify, nil)
|
54
52
|
ensure
|
55
53
|
notify_uninit
|
@@ -57,18 +55,18 @@ module Libnotify
|
|
57
55
|
|
58
56
|
def timeout=(timeout)
|
59
57
|
@timeout = case timeout
|
60
|
-
when NilClass, FalseClass
|
61
|
-
-1
|
62
58
|
when Float
|
63
59
|
(timeout * 1000).to_i
|
64
60
|
when Fixnum
|
65
|
-
if timeout
|
61
|
+
if timeout >= 100 # assume miliseconds
|
66
62
|
timeout
|
67
63
|
else
|
68
64
|
timeout * 1000
|
69
65
|
end
|
66
|
+
when NilClass, FalseClass
|
67
|
+
nil
|
70
68
|
else
|
71
|
-
timeout.to_i
|
69
|
+
timeout.to_s.to_i
|
72
70
|
end
|
73
71
|
end
|
74
72
|
end
|
@@ -79,8 +77,8 @@ if $0 == __FILE__
|
|
79
77
|
Libnotify.new do |notify|
|
80
78
|
notify.summary = "world"
|
81
79
|
notify.body = "hello"
|
82
|
-
notify.timeout = 1.5 #
|
83
|
-
notify.urgency = :critical #
|
80
|
+
notify.timeout = 1.5 # 1.5 (sec), 1000 (ms), "2", nil, false
|
81
|
+
notify.urgency = :critical # :low, :normal, :critical
|
84
82
|
notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
|
85
83
|
notify.show!
|
86
84
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
context Libnotify do
|
4
|
+
setup { Libnotify }
|
5
|
+
|
6
|
+
asserts("responds to new").respond_to(:new)
|
7
|
+
asserts("responds to show").respond_to(:show)
|
8
|
+
|
9
|
+
asserts("#new calls API#new") do
|
10
|
+
mock(Libnotify::API).new(hash_including(:body => "test"))
|
11
|
+
Libnotify.new(:body => "test")
|
12
|
+
RR.verify
|
13
|
+
end
|
14
|
+
asserts("#show calls API#show") do
|
15
|
+
mock(Libnotify::API).show(hash_including(:body => "test"))
|
16
|
+
Libnotify.show(:body => "test")
|
17
|
+
RR.verify
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context Libnotify::API do
|
22
|
+
setup { Libnotify::API }
|
23
|
+
|
24
|
+
context "without options and block" do
|
25
|
+
setup { topic.new }
|
26
|
+
|
27
|
+
asserts("summary is whitspaced") { topic.summary }.equals(" ")
|
28
|
+
asserts("body is whitspaced") { topic.body }.equals(" ")
|
29
|
+
asserts("urgency is :normal") { topic.urgency }.equals(:normal)
|
30
|
+
asserts("timeout is nil") { topic.timeout }.nil
|
31
|
+
asserts("icon_path is nil") { topic.icon_path }.nil
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with options and block" do
|
35
|
+
setup do
|
36
|
+
topic.new(:summary => "hello", :body => "body", :invalid_option => 23) do |n|
|
37
|
+
n.body = "overwritten"
|
38
|
+
n.icon_path = "/path/to/icon"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
asserts("summary is set") { topic.summary }.equals("hello")
|
43
|
+
asserts("body was overwritten by block") { topic.body }.equals("overwritten")
|
44
|
+
asserts("icon_path set") { topic.icon_path }.equals("/path/to/icon")
|
45
|
+
end
|
46
|
+
|
47
|
+
context "timeout=" do
|
48
|
+
setup { topic.new }
|
49
|
+
|
50
|
+
asserts("with float") { topic.timeout = 2.5; topic.timeout }.equals(2500)
|
51
|
+
asserts("with fixnum ms") { topic.timeout = 100; topic.timeout }.equals(100)
|
52
|
+
asserts("with fixnum ms") { topic.timeout = 101; topic.timeout }.equals(101)
|
53
|
+
asserts("with fixnum seconds") { topic.timeout = 1; topic.timeout }.equals(1000)
|
54
|
+
asserts("with fixnum seconds") { topic.timeout = 99; topic.timeout }.equals(99000)
|
55
|
+
asserts("with nil") { topic.timeout = nil; topic.timeout }.nil
|
56
|
+
asserts("with false") { topic.timeout = false; topic.timeout }.nil
|
57
|
+
asserts("with to_s.to_i") { topic.timeout = :"2 seconds"; topic.timeout }.equals(2)
|
58
|
+
end
|
59
|
+
|
60
|
+
# TODO mock this!
|
61
|
+
context "show!" do
|
62
|
+
setup { topic.new(:timeout => 1.0, :icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg") }
|
63
|
+
|
64
|
+
[ :low, :normal, :critical ].each do |urgency|
|
65
|
+
asserts("with urgency #{urgency}") do
|
66
|
+
topic.summary = "#{RUBY_VERSION} at #{RUBY_PLATFORM}"
|
67
|
+
topic.body = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : '?'
|
68
|
+
topic.urgency = urgency; topic.show!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libnotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Suschlik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-08 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,36 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: riot
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: riot_notifier
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rr
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
25
55
|
description:
|
26
56
|
email: peter-libnotify@suschlik.de
|
27
57
|
executables: []
|
@@ -32,10 +62,13 @@ extra_rdoc_files:
|
|
32
62
|
- README.rdoc
|
33
63
|
files:
|
34
64
|
- .gitignore
|
65
|
+
- .watchr
|
35
66
|
- README.rdoc
|
36
67
|
- Rakefile
|
37
68
|
- VERSION
|
38
69
|
- lib/libnotify.rb
|
70
|
+
- test/helper.rb
|
71
|
+
- test/test_libnotify.rb
|
39
72
|
has_rdoc: true
|
40
73
|
homepage: http://github.com/splattael/libnotify
|
41
74
|
licenses: []
|
@@ -64,5 +97,5 @@ rubygems_version: 1.3.5
|
|
64
97
|
signing_key:
|
65
98
|
specification_version: 3
|
66
99
|
summary: Ruby bindings for libnotify using FFI
|
67
|
-
test_files:
|
68
|
-
|
100
|
+
test_files:
|
101
|
+
- test/test_libnotify.rb
|