libnotify 0.5.1 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  doc
2
- pkg
3
2
  coverage
3
+ pkg
4
4
  tags
5
5
  .yardoc
6
6
  .bundle
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- RUBIES = %w[ree 1.9.2 jruby]
5
-
6
4
  require 'rake'
7
5
  require 'rake/rdoctask'
8
6
  require 'rubygems'
7
+ load 'libnotify/tasks/rubies.rake'
9
8
 
10
9
  # Test
11
10
  require 'rake/testtask'
@@ -17,20 +16,6 @@ Rake::TestTask.new(:test) do |test|
17
16
  test.libs << 'test'
18
17
  test.verbose = true
19
18
  end
20
-
21
- desc "Test with several ruby versions"
22
- task :"test:rubies" do
23
- command = "bundle check || bundle install && rake"
24
- RUBIES.each do |ruby|
25
- rvm = "#{ruby}@libnotify"
26
- puts "\n" * 3
27
- puts "RVM: #{rvm}"
28
- puts "=" * 40
29
-
30
- system %{rvm #{rvm} exec bash -c '#{command}'}
31
- end
32
- end
33
-
34
19
  # Yard
35
20
  begin
36
21
  require 'yard'
data/lib/libnotify/api.rb CHANGED
@@ -14,11 +14,27 @@ module Libnotify
14
14
  end
15
15
 
16
16
  self.icon_dirs = [
17
- "/usr/share/icons/gnome/48x48/emblems",
18
- "/usr/share/icons/gnome/256x256/emblems",
19
- "/usr/share/icons/gnome/*/emblems"
17
+ "/usr/share/icons/gnome/*/emblems",
18
+ "/usr/share/icons/gnome/*/emotes"
20
19
  ]
21
20
 
21
+ # TODO refactor & test!
22
+ ICON_REGEX = /(\d+)x\d/
23
+ ICON_SORTER = proc do |a, b|
24
+ ma = a.scan ICON_REGEX
25
+ mb = b.scan ICON_REGEX
26
+
27
+ if ma.first && mb.first
28
+ mb.first.first.to_i <=> ma.first.first.to_i
29
+ elsif ma.first && !mb.first
30
+ 1
31
+ elsif !ma.first && ma.first
32
+ -1
33
+ else
34
+ a <=> b
35
+ end
36
+ end
37
+
22
38
  # Creates a notification object.
23
39
  #
24
40
  # @see Libnotify.new
@@ -42,7 +58,7 @@ module Libnotify
42
58
  def show!
43
59
  notify_init(self.class.to_s) or raise "notify_init failed"
44
60
  notify = notify_notification_new(summary, body, icon_path, nil)
45
- notify_notification_set_urgency(notify, urgency)
61
+ notify_notification_set_urgency(notify, lookup_urgency(urgency))
46
62
  notify_notification_set_timeout(notify, timeout || -1)
47
63
  if append
48
64
  notify_notification_set_hint_string(notify, "x-canonical-append", "")
@@ -82,15 +98,8 @@ module Libnotify
82
98
  when /^\// # absolute
83
99
  @icon_path = path
84
100
  when String
85
- # TODO refactor!
86
- self.class.icon_dirs.map { |d| Dir[d] }.flatten.uniq.each do |dir|
87
- full_path = File.join(dir, path)
88
- if File.exist?(full_path)
89
- @icon_path = full_path
90
- return
91
- end
92
- end
93
- @icon_path = path
101
+ list = self.class.icon_dirs.map { |d| Dir[File.join(d, path)] }.flatten.sort(&ICON_SORTER)
102
+ @icon_path = list.detect { |full_path| File.exist?(full_path) } || path
94
103
  when Symbol
95
104
  self.icon_path = "#{path}.png"
96
105
  else
data/lib/libnotify/ffi.rb CHANGED
@@ -11,19 +11,23 @@ module Libnotify
11
11
  warn e.message
12
12
  end
13
13
 
14
- enum :urgency, [ :low, :normal, :critical ]
14
+ URGENCY = [ :low, :normal, :critical ]
15
15
 
16
16
  def self.attach_functions!
17
17
  attach_function :notify_init, [:string], :bool
18
18
  attach_function :notify_uninit, [], :void
19
19
  attach_function :notify_notification_new, [:string, :string, :string, :pointer], :pointer
20
- attach_function :notify_notification_set_urgency, [:pointer, :urgency], :void
20
+ attach_function :notify_notification_set_urgency, [:pointer, :int], :void
21
21
  attach_function :notify_notification_set_timeout, [:pointer, :long], :void
22
22
  attach_function :notify_notification_set_hint_string, [:pointer, :string, :string], :void
23
23
  attach_function :notify_notification_clear_hints, [:pointer], :void
24
24
  attach_function :notify_notification_show, [:pointer, :pointer], :bool
25
25
  end
26
26
 
27
+ def lookup_urgency(urgency)
28
+ URGENCY.index(urgency)
29
+ end
30
+
27
31
  def method_missing(method, *args, &block)
28
32
  if method.to_s =~ /^notify_/
29
33
  warn "libnotify.so not found!"
@@ -0,0 +1,44 @@
1
+ SUPPORTED_RUBIES = %w[ree 1.9.2 jruby rbx]
2
+
3
+ GEMSPEC = Bundler::GemHelper.new(Dir.pwd).gemspec
4
+
5
+ def with_rubies(command)
6
+ SUPPORTED_RUBIES.each do |ruby|
7
+ with_ruby(ruby, command)
8
+ end
9
+ end
10
+
11
+ def with_ruby(ruby, command)
12
+ rvm = "#{ruby}@#{GEMSPEC.name}"
13
+ command = %{rvm #{rvm} exec bash -c '#{command}'}
14
+
15
+ puts "\n" * 3
16
+ puts "CMD: #{command}"
17
+ puts "=" * 40
18
+
19
+ system command
20
+ end
21
+
22
+ namespace :rubies do
23
+ desc "Run tests for following supported platforms #{SUPPORTED_RUBIES.inspect}"
24
+ task :test do
25
+ command = "bundle check || bundle install && rake"
26
+ with_rubies(command)
27
+ end
28
+
29
+ desc "Build gems for following supported platforms #{SUPPORTED_RUBIES.inspect}"
30
+ task :build do
31
+ command = "rake build"
32
+ with_rubies(command)
33
+ end
34
+
35
+ desc "Pushes gems for following supported platforms #{SUPPORTED_RUBIES.inspect}"
36
+ task :push => :build do
37
+ Dir[File.join("pkg", "#{GEMSPEC.name}-#{GEMSPEC.version}*.gem")].each do |gem|
38
+ command = "gem push #{gem}"
39
+ puts command
40
+ system command
41
+ end
42
+ end
43
+
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Libnotify
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.4"
3
3
  end
data/libnotify.gemspec CHANGED
@@ -2,10 +2,21 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "libnotify"
4
4
 
5
+ platform = Gem::Platform::RUBY
6
+ needs_ffi = true
7
+
8
+ if RUBY_PLATFORM =~ /java/
9
+ needs_ffi = false
10
+ platform = "java"
11
+ elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
12
+ needs_ffi = false
13
+ platform = Gem::Platform::new ['universal', 'rubinius', '1.2']
14
+ end
15
+
5
16
  Gem::Specification.new do |s|
6
17
  s.name = "libnotify"
7
18
  s.version = Libnotify::VERSION
8
- s.platform = Gem::Platform::RUBY
19
+ s.platform = platform
9
20
  s.authors = ["Peter Suschlik"]
10
21
  s.email = ["peter-libnotify@suschlik.de"]
11
22
  s.homepage = "http://rubygems.org/gems/libnotify"
@@ -16,8 +27,10 @@ Gem::Specification.new do |s|
16
27
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
28
  s.require_paths = ["lib"]
18
29
 
19
- s.add_runtime_dependency 'ffi', '~> 1.0'
30
+ if needs_ffi
31
+ s.add_runtime_dependency 'ffi', '~> 1.0'
32
+ end
20
33
 
21
34
  s.add_development_dependency 'minitest'
22
- s.add_development_dependency 'yard'
35
+ s.add_development_dependency 'yard', '~> 0.7.0'
23
36
  end
Binary file
data/test/helper.rb CHANGED
@@ -3,3 +3,4 @@ require 'bundler/setup'
3
3
  require 'minitest/autorun'
4
4
 
5
5
  require 'libnotify'
6
+ require 'libnotify_io'
@@ -0,0 +1,36 @@
1
+ class LibnotifyIO
2
+ attr_reader :io, :libnotify
3
+
4
+ def initialize io
5
+ @io = io
6
+ @libnotify = begin
7
+ require 'libnotify'
8
+ Libnotify.new(:timeout => 2.5, :append => false)
9
+ end
10
+ end
11
+
12
+ def puts *o
13
+ if o.first =~ /(\d+) failures, (\d+) errors/
14
+ description = [ RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM ].join(" ")
15
+ libnotify.body = o.first
16
+ if $1.to_i > 0 || $2.to_i > 0 # fail?
17
+ libnotify.summary = ":-( #{description}"
18
+ libnotify.urgency = :critical
19
+ libnotify.icon_path = "face-angry.*"
20
+ else
21
+ libnotify.summary += ":-) #{description}"
22
+ libnotify.urgency = :normal
23
+ libnotify.icon_path = "face-laugh.*"
24
+ end
25
+ libnotify.show!
26
+ else
27
+ io.puts *o
28
+ end
29
+ end
30
+
31
+ def method_missing msg, *args
32
+ io.send(msg, *args)
33
+ end
34
+ end
35
+
36
+ MiniTest::Unit.output = LibnotifyIO.new(MiniTest::Unit.output)
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libnotify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
5
+ version: 0.5.4
11
6
  platform: ruby
12
7
  authors:
13
8
  - Peter Suschlik
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-12 00:00:00 +02:00
13
+ date: 2011-05-24 00:00:00 +02:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,10 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
24
  version: "1.0"
34
25
  type: :runtime
35
26
  version_requirements: *id001
@@ -41,9 +32,6 @@ dependencies:
41
32
  requirements:
42
33
  - - ">="
43
34
  - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
35
  version: "0"
48
36
  type: :development
49
37
  version_requirements: *id002
@@ -53,12 +41,9 @@ dependencies:
53
41
  requirement: &id003 !ruby/object:Gem::Requirement
54
42
  none: false
55
43
  requirements:
56
- - - ">="
44
+ - - ~>
57
45
  - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
46
+ version: 0.7.0
62
47
  type: :development
63
48
  version_requirements: *id003
64
49
  description:
@@ -80,10 +65,15 @@ files:
80
65
  - lib/libnotify.rb
81
66
  - lib/libnotify/api.rb
82
67
  - lib/libnotify/ffi.rb
68
+ - lib/libnotify/tasks/rubies.rake
83
69
  - lib/libnotify/version.rb
84
70
  - libnotify.gemspec
85
71
  - libnotify.png
72
+ - pkg/libnotify-0.5.3-universal-java-1.6.gem
73
+ - pkg/libnotify-0.5.3-universal-rubinius-1.2.gem
74
+ - pkg/libnotify-0.5.3-x86-linux.gem
86
75
  - test/helper.rb
76
+ - test/libnotify_io.rb
87
77
  - test/test_libnotify.rb
88
78
  has_rdoc: true
89
79
  homepage: http://rubygems.org/gems/libnotify
@@ -99,18 +89,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
89
  requirements:
100
90
  - - ">="
101
91
  - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
92
  version: "0"
106
93
  required_rubygems_version: !ruby/object:Gem::Requirement
107
94
  none: false
108
95
  requirements:
109
96
  - - ">="
110
97
  - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
98
  version: "0"
115
99
  requirements: []
116
100
 
@@ -119,5 +103,7 @@ rubygems_version: 1.6.2
119
103
  signing_key:
120
104
  specification_version: 3
121
105
  summary: Ruby bindings for libnotify using FFI
122
- test_files: []
123
-
106
+ test_files:
107
+ - test/helper.rb
108
+ - test/libnotify_io.rb
109
+ - test/test_libnotify.rb