Skip to content

Commit

Permalink
Merge branch 'master' of github.com:splattael/libnotify
Browse files Browse the repository at this point in the history
  • Loading branch information
splattael committed Feb 6, 2010
2 parents 1f8e7ab + 1d20a40 commit 44dc58f
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 43 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,3 @@ doc
pkg
coverage
tags
*.gemspec
21 changes: 0 additions & 21 deletions .watchr

This file was deleted.

12 changes: 9 additions & 3 deletions README.rdoc
@@ -1,6 +1,10 @@
= 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] |
Metrics[http://getcaliper.com/caliper/project?repo=http%3A%2F%2Fgemcutter.org%2Fgems%2Flibnotify]

== Usage

Expand Down Expand Up @@ -28,7 +32,7 @@ Ruby binding for libnotify using FFI.

gem install libnotify

You need libnotify. On Debian you can just do:
You'll need libnotify. On Debian just type:

apt-get install libnotify1

Expand All @@ -37,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 with rrriot. (test/test_libnotify.rb:60)
10 changes: 10 additions & 0 deletions Rakefile
@@ -1,5 +1,6 @@
require 'rake'
require 'rake/rdoctask'
require 'rubygems'

begin
require 'jeweler'
Expand Down Expand Up @@ -59,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
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.0.4
0.1.0
32 changes: 16 additions & 16 deletions 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)
Expand All @@ -10,6 +13,7 @@ def self.show(*args, &block)
API.show(*args, &block)
end

# Raw FFI bindings.
module FFI
extend ::FFI::Library

Expand All @@ -33,20 +37,23 @@ def self.ffi_lib(libs)

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"
Expand All @@ -59,6 +66,7 @@ def show!
end

def timeout=(timeout)
# TODO Simplify timeout=
@timeout = case timeout
when Float
(timeout * 1000).to_i
Expand All @@ -74,19 +82,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
59 changes: 59 additions & 0 deletions libnotify.gemspec
@@ -0,0 +1,59 @@
# 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.1.0"

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",
"README.rdoc",
"Rakefile",
"VERSION",
"lib/libnotify.rb",
"libnotify.gemspec",
"test.watchr",
"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<ffi>, [">= 0"])
s.add_development_dependency(%q<riot>, [">= 0"])
s.add_development_dependency(%q<riot_notifier>, [">= 0.0.7"])
s.add_development_dependency(%q<rr>, [">= 0"])
else
s.add_dependency(%q<ffi>, [">= 0"])
s.add_dependency(%q<riot>, [">= 0"])
s.add_dependency(%q<riot_notifier>, [">= 0.0.7"])
s.add_dependency(%q<rr>, [">= 0"])
end
else
s.add_dependency(%q<ffi>, [">= 0"])
s.add_dependency(%q<riot>, [">= 0"])
s.add_dependency(%q<riot_notifier>, [">= 0.0.7"])
s.add_dependency(%q<rr>, [">= 0"])
end
end

15 changes: 15 additions & 0 deletions 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 }
2 changes: 1 addition & 1 deletion test/test_libnotify.rb
Expand Up @@ -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 with rrriot.
context "show!" do
setup { topic.new(:timeout => 1.0, :icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg") }

Expand Down

0 comments on commit 44dc58f

Please sign in to comment.