From f2a1c307866ebf1aefebfbb22ce387a7cb0dd911 Mon Sep 17 00:00:00 2001 From: "Jeremy Lawler (papyrus)" Date: Fri, 5 Feb 2010 19:45:08 +0800 Subject: [PATCH 01/13] explicitly require rubygems for atypical rake installs rake from ubuntu's deb package doesn't require rubygems --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 1dde521..6f9cd80 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ require 'rake' require 'rake/rdoctask' +require 'rubygems' begin require 'jeweler' From 5a4ba9f80570ad1b578727c09fc17f3b4b0e2bfa Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 21:42:30 +0100 Subject: [PATCH 02/13] Version bump to 0.0.5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 81340c7..bbdeab6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.4 +0.0.5 From 66b48b1070739b80e140b7eb4432036e8c582db8 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 21:43:11 +0100 Subject: [PATCH 03/13] Ok, don't ignore gemspec from now. --- .gitignore | 1 - libnotify.gemspec | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 libnotify.gemspec diff --git a/.gitignore b/.gitignore index 084fa03..2a7914b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ doc pkg coverage tags -*.gemspec diff --git a/libnotify.gemspec b/libnotify.gemspec new file mode 100644 index 0000000..2076f1a --- /dev/null +++ b/libnotify.gemspec @@ -0,0 +1,58 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{libnotify} + s.version = "0.0.5" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Peter Suschlik"] + s.date = %q{2010-02-05} + s.email = %q{peter-libnotify@suschlik.de} + s.extra_rdoc_files = [ + "README.rdoc" + ] + s.files = [ + ".gitignore", + ".watchr", + "README.rdoc", + "Rakefile", + "VERSION", + "lib/libnotify.rb", + "test/helper.rb", + "test/test_libnotify.rb" + ] + s.homepage = %q{http://github.com/splattael/libnotify} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.5} + s.summary = %q{Ruby bindings for libnotify using FFI} + s.test_files = [ + "test/test_libnotify.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0.0.7"]) + s.add_development_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0.0.7"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0.0.7"]) + s.add_dependency(%q, [">= 0"]) + end +end + From 05ed27fe8f9718034646fa753805bd5f157e9aca Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 21:43:54 +0100 Subject: [PATCH 04/13] Regenerated gemspec for version 0.0.5 --- libnotify.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/libnotify.gemspec b/libnotify.gemspec index 2076f1a..5bd5c95 100644 --- a/libnotify.gemspec +++ b/libnotify.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| "Rakefile", "VERSION", "lib/libnotify.rb", + "libnotify.gemspec", "test/helper.rb", "test/test_libnotify.rb" ] From ae428ca157f32cea7bc651d431b3c23ac654eb27 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 21:54:50 +0100 Subject: [PATCH 05/13] Add some useful links to README. --- README.rdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rdoc b/README.rdoc index fade3ad..cafaf3a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -2,6 +2,10 @@ Ruby binding for libnotify using FFI. +Source[http://github.com/splattael/libnotify] | +RDoc[http://rdoc.info/projects/splattael/libnotify] | +Metrics[http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fsplattael%libnotify.git] + == Usage require 'libnotify' From eeb8f9588f61d30bf7b2a98d637cbd2057bdfadd Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 21:58:08 +0100 Subject: [PATCH 06/13] Polish test.watchr. --- .watchr | 21 --------------------- test.watchr | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 21 deletions(-) delete mode 100644 .watchr create mode 100755 test.watchr diff --git a/.watchr b/.watchr deleted file mode 100644 index 2e722c8..0000000 --- a/.watchr +++ /dev/null @@ -1,21 +0,0 @@ - -def run(*args) - system "ruby -rubygems -Ilib:test #{args.join(' ')}" -end - -def run_tests - system "rake test" -end - -def underscore(file) - file.gsub('/', '_') -end - -watch('test/test_.*\.rb') {|md| run md[0] } -watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" } -watch('test/helper.rb') { run_tests } - -run_tests - -Signal.trap("QUIT") { abort("\n") } -Signal.trap("INT") { run_tests } diff --git a/test.watchr b/test.watchr new file mode 100755 index 0000000..fdb9f22 --- /dev/null +++ b/test.watchr @@ -0,0 +1,15 @@ +#!/usr/bin/env watchr + +begin + require File.join(ENV["HOME"], ".watchr.test.rb") +rescue LoadError + warn "Unable to load #{File.join(ENV["HOME"], ".watchr.test.rb")}" + warn "You might try this: http://gist.github.com/raw/273574/8804dff44b104e9b8706826dc8882ed985b4fd13/.watchr.test.rb" + exit +end + +run_tests + +watch('test/test_.*\.rb') {|md| run md[0] } +watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" } +watch('test/helper.rb') { run_tests } From 8913435af4d04dec84491e8b8c0bda50f6b9369f Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:26:23 +0100 Subject: [PATCH 07/13] Some cleanup: typos, todos. --- README.rdoc | 6 ++++-- Rakefile | 9 +++++++++ lib/libnotify.rb | 32 ++++++++++++++++---------------- test/test_libnotify.rb | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.rdoc b/README.rdoc index cafaf3a..d22414a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,6 +1,6 @@ = Libnotify -Ruby binding for libnotify using FFI. +Ruby bindings for libnotify using FFI. Source[http://github.com/splattael/libnotify] | RDoc[http://rdoc.info/projects/splattael/libnotify] | @@ -41,4 +41,6 @@ You need libnotify. On Debian you can just do: == TODO -* Mock FFI calls +* Empty strings give warnings (lib/libnotify.rb:46) +* Simplify timeout= (lib/libnotify.rb:64) +* Mock FFI calls (test/test_libnotify.rb:60) diff --git a/Rakefile b/Rakefile index 6f9cd80..f803765 100644 --- a/Rakefile +++ b/Rakefile @@ -60,3 +60,12 @@ desc "Find whitespace at line ends" task :eol do system "grep -nrE ' +$' *" end + +desc "Display TODOs" +task :todo do + `grep -Inr TODO lib test`.each do |line| + line.scan(/^(.*?:.*?):\s*#\s*TODO\s*(.*)$/) do |(file, todo)| + puts "* #{todo} (#{file})" + end + end +end diff --git a/lib/libnotify.rb b/lib/libnotify.rb index 35a9da0..5855dfa 100644 --- a/lib/libnotify.rb +++ b/lib/libnotify.rb @@ -1,5 +1,8 @@ require 'ffi' +# Ruby bindings for libnotify using FFI. +# +# See README.rdoc for usage examples. module Libnotify def self.new(*args, &block) @@ -10,6 +13,7 @@ def self.show(*args, &block) API.show(*args, &block) end + # Raw FFI bindings. module FFI extend ::FFI::Library @@ -28,20 +32,23 @@ module FFI class API include FFI + attr_reader :timeout attr_accessor :summary, :body, :icon_path, :urgency def initialize(options = {}, &block) - self.summary = self.body = " " # Empty strings gives warnings... - self.urgency = :normal - self.timeout = nil + set_defaults options.each { |key, value| send("#{key}=", value) if respond_to?(key) } yield(self) if block_given? end - def self.show(*args, &block) - new(*args, &block).show! + def set_defaults + # TODO Empty strings give warnings + self.summary = self.body = " " + self.urgency = :normal + self.timeout = nil end + private :set_defaults def show! notify_init(self.class.to_s) or raise "notify_init failed" @@ -54,6 +61,7 @@ def show! end def timeout=(timeout) + # TODO Simplify timeout= @timeout = case timeout when Float (timeout * 1000).to_i @@ -69,19 +77,11 @@ def timeout=(timeout) timeout.to_s.to_i end end - end -end + def self.show(*args, &block) + new(*args, &block).show! + end -if $0 == __FILE__ - Libnotify.new do |notify| - notify.summary = "world" - notify.body = "hello" - notify.timeout = 1.5 # 1.5 (sec), 1000 (ms), "2", nil, false - notify.urgency = :critical # :low, :normal, :critical - notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg" - notify.show! end - Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5) end diff --git a/test/test_libnotify.rb b/test/test_libnotify.rb index 196419b..5d7e203 100644 --- a/test/test_libnotify.rb +++ b/test/test_libnotify.rb @@ -57,7 +57,7 @@ asserts("with to_s.to_i") { topic.timeout = :"2 seconds"; topic.timeout }.equals(2) end - # TODO mock this! + # TODO Mock FFI calls context "show!" do setup { topic.new(:timeout => 1.0, :icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg") } From 721a7df38afd153e40ad3063ff46884e9b05aa4b Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:30:15 +0100 Subject: [PATCH 08/13] Update TODO. --- README.rdoc | 2 +- test/test_libnotify.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rdoc b/README.rdoc index d22414a..de5f7c4 100644 --- a/README.rdoc +++ b/README.rdoc @@ -43,4 +43,4 @@ You need libnotify. On Debian you can just do: * Empty strings give warnings (lib/libnotify.rb:46) * Simplify timeout= (lib/libnotify.rb:64) -* Mock FFI calls (test/test_libnotify.rb:60) +* Mock FFI calls with rrriot. (test/test_libnotify.rb:60) diff --git a/test/test_libnotify.rb b/test/test_libnotify.rb index 5d7e203..89305a6 100644 --- a/test/test_libnotify.rb +++ b/test/test_libnotify.rb @@ -57,7 +57,7 @@ asserts("with to_s.to_i") { topic.timeout = :"2 seconds"; topic.timeout }.equals(2) end - # TODO Mock FFI calls + # TODO Mock FFI calls with rrriot. context "show!" do setup { topic.new(:timeout => 1.0, :icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg") } From fd10c06d5199446431a27aad00d5014510548525 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:37:46 +0100 Subject: [PATCH 09/13] Kill empty lines. --- test.watchr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.watchr b/test.watchr index fdb9f22..143e9af 100755 --- a/test.watchr +++ b/test.watchr @@ -1,5 +1,5 @@ #!/usr/bin/env watchr - + begin require File.join(ENV["HOME"], ".watchr.test.rb") rescue LoadError @@ -7,9 +7,9 @@ rescue LoadError warn "You might try this: http://gist.github.com/raw/273574/8804dff44b104e9b8706826dc8882ed985b4fd13/.watchr.test.rb" exit end - + run_tests - + watch('test/test_.*\.rb') {|md| run md[0] } watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" } watch('test/helper.rb') { run_tests } From 1f04f40ba354e8464e016a5d8fe6721811176be4 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:42:57 +0100 Subject: [PATCH 10/13] Fix link to metrics. --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index de5f7c4..3d7a02e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -4,7 +4,7 @@ Ruby bindings for libnotify using FFI. Source[http://github.com/splattael/libnotify] | RDoc[http://rdoc.info/projects/splattael/libnotify] | -Metrics[http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fsplattael%libnotify.git] +Metrics[http://getcaliper.com/caliper/project?repo=http%3A%2F%2Fgemcutter.org%2Fgems%2Flibnotify] == Usage From e2a15d9106b9fefbad7b64652a0f025a7299039e Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:47:08 +0100 Subject: [PATCH 11/13] README, again. --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 3d7a02e..523069c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -32,7 +32,7 @@ Metrics[http://getcaliper.com/caliper/project?repo=http%3A%2F%2Fgemcutter.org%2F gem install libnotify -You need libnotify. On Debian you can just do: +You'll need libnotify. On Debian just type: apt-get install libnotify1 From 603a8eccf3c734e2dfe4da24cf096c22a229cfc1 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:47:44 +0100 Subject: [PATCH 12/13] Version bump to 0.1.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index bbdeab6..6e8bf73 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.5 +0.1.0 From 1d20a40653b70a4ec3dfebb219f928a9aa97af28 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Fri, 5 Feb 2010 22:48:25 +0100 Subject: [PATCH 13/13] Regenerated gemspec for version 0.1.0 --- libnotify.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnotify.gemspec b/libnotify.gemspec index 5bd5c95..7fd3f1e 100644 --- a/libnotify.gemspec +++ b/libnotify.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{libnotify} - s.version = "0.0.5" + s.version = "0.1.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Peter Suschlik"] @@ -16,12 +16,12 @@ Gem::Specification.new do |s| ] s.files = [ ".gitignore", - ".watchr", "README.rdoc", "Rakefile", "VERSION", "lib/libnotify.rb", "libnotify.gemspec", + "test.watchr", "test/helper.rb", "test/test_libnotify.rb" ]