opener 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.markdown +64 -0
  2. data/lib/opener.rb +105 -0
  3. data/opener.gemspec +16 -0
  4. metadata +48 -0
data/README.markdown ADDED
@@ -0,0 +1,64 @@
1
+ # Opener
2
+
3
+ Opener is a Ruby library for opening things in an cross-platform way.
4
+
5
+ It is a tiny (28 lines of code) alternative to Ruby's [launchy] gem.
6
+
7
+ [launchy]: http://rubygems.org/gems/launchy
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'opener'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install opener
22
+
23
+ ## Usage
24
+
25
+ Load this library:
26
+
27
+ require 'opener'
28
+
29
+ Open something in the foreground (blocking call):
30
+
31
+ Opener.system(thing_to_open_in_foreground)
32
+
33
+ Open something in the foreground while suppressing output:
34
+
35
+ Opener.system(thing_to_open_in_foreground, 1 => :close)
36
+
37
+ Open something in the foreground while suppressing errors:
38
+
39
+ Opener.system(thing_to_open_in_foreground, 2 => :close)
40
+
41
+ Open something in the background (non-blocking call):
42
+
43
+ Opener.spawn(thing_to_open_in_background)
44
+
45
+ Open something in the background while suppressing output:
46
+
47
+ Opener.spawn(thing_to_open_in_background, 1 => :close)
48
+
49
+ Open something in the background while suppressing errors:
50
+
51
+ Opener.spawn(thing_to_open_in_background, 2 => :close)
52
+
53
+ Reveal the OS-specific command that is opening things:
54
+
55
+ puts Opener.command()
56
+
57
+ ## License
58
+
59
+ This library is distributed under the same terms as Ruby:
60
+ <http://www.ruby-lang.org/en/about/license.txt>
61
+
62
+ Copyright 2013 Suraj N. Kurapati <https://github.com/sunaku>
63
+
64
+ Thanks to 2010 David A. Wheeler <http://www.dwheeler.com/essays/open-files-urls.html>
data/lib/opener.rb ADDED
@@ -0,0 +1,105 @@
1
+ require 'rbconfig'
2
+
3
+ #
4
+ # Ruby library for opening things in an cross-platform way.
5
+ #
6
+ # == Usage
7
+ #
8
+ # Load this library:
9
+ #
10
+ # require 'opener'
11
+ #
12
+ # Open something in the foreground (blocking call):
13
+ #
14
+ # Opener.system(thing_to_open_in_foreground)
15
+ #
16
+ # Open something in the foreground while suppressing output:
17
+ #
18
+ # Opener.system(thing_to_open_in_foreground, 1 => :close)
19
+ #
20
+ # Open something in the foreground while suppressing errors:
21
+ #
22
+ # Opener.system(thing_to_open_in_foreground, 2 => :close)
23
+ #
24
+ # Open something in the background (non-blocking call):
25
+ #
26
+ # Opener.spawn(thing_to_open_in_background)
27
+ #
28
+ # Open something in the background while suppressing output:
29
+ #
30
+ # Opener.spawn(thing_to_open_in_background, 1 => :close)
31
+ #
32
+ # Open something in the background while suppressing errors:
33
+ #
34
+ # Opener.spawn(thing_to_open_in_background, 2 => :close)
35
+ #
36
+ # Reveal the OS-specific command that is opening things:
37
+ #
38
+ # puts Opener.command()
39
+ #
40
+ # == License
41
+ #
42
+ # This library is distributed under the same terms as Ruby:
43
+ # <http://www.ruby-lang.org/en/about/license.txt>
44
+ #
45
+ # Copyright 2013 Suraj N. Kurapati <https://github.com/sunaku>
46
+ #
47
+ # Thanks to 2010 David A. Wheeler <http://www.dwheeler.com/essays/open-files-urls.html>
48
+ #
49
+ module Opener
50
+ class << self
51
+
52
+ #
53
+ # Returns an OS-specific command for opening things.
54
+ #
55
+ # http://www.dwheeler.com/essays/open-files-urls.html
56
+ # http://www.par.univie.ac.at/solaris/cde-www/
57
+ #
58
+ def command
59
+ @command ||=
60
+ case RbConfig::CONFIG['host_os']
61
+ when /darwin/i then 'open'
62
+ when /cygwin/i then 'cygstart'
63
+ when /linux|bsd/i then 'xdg-open'
64
+ when /mswin|mingw/i then 'start'
65
+ when /sunos|solaris/i then '/usr/dt/bin/sdtwebclient'
66
+ end
67
+ end
68
+
69
+ #
70
+ # Opens the given things in the foreground.
71
+ #
72
+ # @see Kernel#system()
73
+ #
74
+ def system *arguments
75
+ insert_command_into_arguments! arguments
76
+ super
77
+ end
78
+
79
+ #
80
+ # Opens the given things in the background.
81
+ #
82
+ # @see Kernel#spawn()
83
+ #
84
+ def spawn *arguments
85
+ insert_command_into_arguments! arguments
86
+ super
87
+ end
88
+
89
+ private
90
+
91
+ #
92
+ # The first argument to Kernel#system() and Kernel#spawn() can be either:
93
+ #
94
+ # * Hash - containing a mapping of environment variables and values
95
+ # * String - containing the first word of the command to be executed
96
+ #
97
+ # This method carefully inserts our Opener.command() before that String.
98
+ #
99
+ def insert_command_into_arguments! arguments
100
+ insertion_point = (arguments[0].kind_of? Hash) ? 1 : 0
101
+ arguments.insert insertion_point, self.command
102
+ end
103
+
104
+ end
105
+ end
data/opener.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = 'opener'
4
+ spec.version = '0.0.1'
5
+ spec.author = 'Suraj N. Kurapati'
6
+ spec.email = 'sunaku@gmail.com'
7
+ spec.description = 'Library for opening things in an cross-platform way.'
8
+ spec.summary = "A 28-line alternative to Ruby's launchy gem."
9
+ spec.homepage = 'https://github.com/sunaku/opener'
10
+ spec.license = 'Ruby'
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opener
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Suraj N. Kurapati
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Library for opening things in an cross-platform way.
15
+ email: sunaku@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.markdown
21
+ - lib/opener.rb
22
+ - opener.gemspec
23
+ homepage: https://github.com/sunaku/opener
24
+ licenses:
25
+ - Ruby
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.25
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: A 28-line alternative to Ruby's launchy gem.
48
+ test_files: []