libnotify 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,10 @@
1
1
  = Libnotify
2
2
 
3
- Ruby binding for libnotify using FFI.
3
+ Ruby bindings for libnotify using FFI.
4
+
5
+ Source[http://github.com/splattael/libnotify] |
6
+ RDoc[http://rdoc.info/projects/splattael/libnotify] |
7
+ Metrics[http://getcaliper.com/caliper/project?repo=http%3A%2F%2Fgemcutter.org%2Fgems%2Flibnotify]
4
8
 
5
9
  == Usage
6
10
 
@@ -28,7 +32,7 @@ Ruby binding for libnotify using FFI.
28
32
 
29
33
  gem install libnotify
30
34
 
31
- You need libnotify. On Debian you can just do:
35
+ You'll need libnotify. On Debian just type:
32
36
 
33
37
  apt-get install libnotify1
34
38
 
@@ -37,4 +41,6 @@ You need libnotify. On Debian you can just do:
37
41
 
38
42
  == TODO
39
43
 
40
- * Mock FFI calls
44
+ * Empty strings give warnings (lib/libnotify.rb:46)
45
+ * Simplify timeout= (lib/libnotify.rb:64)
46
+ * Mock FFI calls with rrriot. (test/test_libnotify.rb:60)
data/Rakefile CHANGED
@@ -60,3 +60,12 @@ desc "Find whitespace at line ends"
60
60
  task :eol do
61
61
  system "grep -nrE ' +$' *"
62
62
  end
63
+
64
+ desc "Display TODOs"
65
+ task :todo do
66
+ `grep -Inr TODO lib test`.each do |line|
67
+ line.scan(/^(.*?:.*?):\s*#\s*TODO\s*(.*)$/) do |(file, todo)|
68
+ puts "* #{todo} (#{file})"
69
+ end
70
+ end
71
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.1.0
data/lib/libnotify.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'ffi'
2
2
 
3
+ # Ruby bindings for libnotify using FFI.
4
+ #
5
+ # See README.rdoc for usage examples.
3
6
  module Libnotify
4
7
 
5
8
  def self.new(*args, &block)
@@ -10,6 +13,7 @@ module Libnotify
10
13
  API.show(*args, &block)
11
14
  end
12
15
 
16
+ # Raw FFI bindings.
13
17
  module FFI
14
18
  extend ::FFI::Library
15
19
 
@@ -28,20 +32,23 @@ module Libnotify
28
32
 
29
33
  class API
30
34
  include FFI
35
+
31
36
  attr_reader :timeout
32
37
  attr_accessor :summary, :body, :icon_path, :urgency
33
38
 
34
39
  def initialize(options = {}, &block)
35
- self.summary = self.body = " " # Empty strings gives warnings...
36
- self.urgency = :normal
37
- self.timeout = nil
40
+ set_defaults
38
41
  options.each { |key, value| send("#{key}=", value) if respond_to?(key) }
39
42
  yield(self) if block_given?
40
43
  end
41
44
 
42
- def self.show(*args, &block)
43
- new(*args, &block).show!
45
+ def set_defaults
46
+ # TODO Empty strings give warnings
47
+ self.summary = self.body = " "
48
+ self.urgency = :normal
49
+ self.timeout = nil
44
50
  end
51
+ private :set_defaults
45
52
 
46
53
  def show!
47
54
  notify_init(self.class.to_s) or raise "notify_init failed"
@@ -54,6 +61,7 @@ module Libnotify
54
61
  end
55
62
 
56
63
  def timeout=(timeout)
64
+ # TODO Simplify timeout=
57
65
  @timeout = case timeout
58
66
  when Float
59
67
  (timeout * 1000).to_i
@@ -69,19 +77,11 @@ module Libnotify
69
77
  timeout.to_s.to_i
70
78
  end
71
79
  end
72
- end
73
80
 
74
- end
81
+ def self.show(*args, &block)
82
+ new(*args, &block).show!
83
+ end
75
84
 
76
- if $0 == __FILE__
77
- Libnotify.new do |notify|
78
- notify.summary = "world"
79
- notify.body = "hello"
80
- notify.timeout = 1.5 # 1.5 (sec), 1000 (ms), "2", nil, false
81
- notify.urgency = :critical # :low, :normal, :critical
82
- notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
83
- notify.show!
84
85
  end
85
86
 
86
- Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
87
87
  end
data/libnotify.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{libnotify}
8
- s.version = "0.0.5"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Suschlik"]
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
16
16
  ]
17
17
  s.files = [
18
18
  ".gitignore",
19
- ".watchr",
20
19
  "README.rdoc",
21
20
  "Rakefile",
22
21
  "VERSION",
23
22
  "lib/libnotify.rb",
24
23
  "libnotify.gemspec",
24
+ "test.watchr",
25
25
  "test/helper.rb",
26
26
  "test/test_libnotify.rb"
27
27
  ]
@@ -57,7 +57,7 @@ context Libnotify::API do
57
57
  asserts("with to_s.to_i") { topic.timeout = :"2 seconds"; topic.timeout }.equals(2)
58
58
  end
59
59
 
60
- # TODO mock this!
60
+ # TODO Mock FFI calls with rrriot.
61
61
  context "show!" do
62
62
  setup { topic.new(:timeout => 1.0, :icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg") }
63
63
 
data/test.watchr ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env watchr
2
+
3
+ begin
4
+ require File.join(ENV["HOME"], ".watchr.test.rb")
5
+ rescue LoadError
6
+ warn "Unable to load #{File.join(ENV["HOME"], ".watchr.test.rb")}"
7
+ warn "You might try this: http://gist.github.com/raw/273574/8804dff44b104e9b8706826dc8882ed985b4fd13/.watchr.test.rb"
8
+ exit
9
+ end
10
+
11
+ run_tests
12
+
13
+ watch('test/test_.*\.rb') {|md| run md[0] }
14
+ watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" }
15
+ watch('test/helper.rb') { run_tests }
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.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Suschlik
@@ -62,12 +62,12 @@ extra_rdoc_files:
62
62
  - README.rdoc
63
63
  files:
64
64
  - .gitignore
65
- - .watchr
66
65
  - README.rdoc
67
66
  - Rakefile
68
67
  - VERSION
69
68
  - lib/libnotify.rb
70
69
  - libnotify.gemspec
70
+ - test.watchr
71
71
  - test/helper.rb
72
72
  - test/test_libnotify.rb
73
73
  has_rdoc: true
data/.watchr DELETED
@@ -1,21 +0,0 @@
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 }