[DRE-commits] [ruby-launchy-shim] 03/04: add `Suggests: xdg-open`, and output a warning if it's not installed.

Antonio Terceiro terceiro at moszumanska.debian.org
Wed Oct 21 16:37:54 UTC 2015


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to branch master
in repository ruby-launchy-shim.

commit 0fbc970827de6a22d112b0a6b97135eb9bb5cd90
Author: Antonio Terceiro <terceiro at softwarelivre.org>
Date:   Wed Oct 21 14:35:19 2015 -0200

    add `Suggests: xdg-open`, and output a warning if it's not installed.
---
 debian/changelog     |  1 +
 debian/control       |  1 +
 lib/launchy.rb       | 12 +++++++++++-
 test/launchy_test.rb | 17 +++++++++++++++--
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index a08903e..2aaae20 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ ruby-launchy-shim (2.3.0.1) UNRELEASED; urgency=medium
 
   * improve package description
   * launchy.gemspec: read version from debian/changelog
+  * add `Suggests: xdg-open`, and output a warning if it's not installed.
 
  -- Antonio Terceiro <terceiro at debian.org>  Wed, 21 Oct 2015 14:18:30 -0200
 
diff --git a/debian/control b/debian/control
index a91a1a5..3523c50 100644
--- a/debian/control
+++ b/debian/control
@@ -19,6 +19,7 @@ XB-Ruby-Versions: ${ruby:Versions}
 Depends: ruby | ruby-interpreter,
          ${misc:Depends},
          ${shlibs:Depends}
+Suggests: xdg-utils
 Description: helper class for launching a web browser
  Launchy is a helper class for launching a web browser in a fire and forget
  manner from Ruby programs. This is a minimal shim that replaces the original
diff --git a/lib/launchy.rb b/lib/launchy.rb
index 0a0cb53..498ccec 100644
--- a/lib/launchy.rb
+++ b/lib/launchy.rb
@@ -1,5 +1,15 @@
 module Launchy
   def self.open(uri, options = {})
-    system('xdg-open', uri)
+    if xdg_open_available
+      system('xdg-open', uri)
+    else
+      puts "W: can't open #{uri} without xdg-open; install the `xdg-utils` package!"
+    end
+  end
+
+  private
+
+  def self.xdg_open_available
+    system('which xdg-open >/dev/null')
   end
 end
diff --git a/test/launchy_test.rb b/test/launchy_test.rb
index 095b412..fc17e90 100644
--- a/test/launchy_test.rb
+++ b/test/launchy_test.rb
@@ -6,11 +6,24 @@ class LaunchyTest < MiniTest::Test
   def test_calls_xdg_open
     args_used = nil
     system = lambda { |*args| args_used = args.clone }
-    Launchy.stub :system, system do
-      Launchy.open('http://www.debian.org/')
+    Launchy.stub :xdg_open_available, true do
+      Launchy.stub :system, system do
+        Launchy.open('http://www.debian.org/')
+      end
     end
 
     assert_equal ['xdg-open', 'http://www.debian.org/'], args_used
   end
 
+  def test_warns_if_xdg_open_is_not_available
+    explode = lambda { |*args| raise Exception.new("should't call xdg-open if it's not installed") }
+    Launchy.stub :xdg_open_available, false do
+      Launchy.stub :system, explode do
+        Launchy.stub :puts, nil do
+          Launchy.open('http://www.debian.org/')
+        end
+      end
+    end
+  end
+
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-launchy-shim.git



More information about the Pkg-ruby-extras-commits mailing list