unix-whereis 0.1.0

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.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "depq", ">= 0.4"
5
+ gem "hash-utils", ">= 0.9.0"
6
+ gem "pipe-run", ">= 0.1.0"
7
+ gem "command-builder", ">= 0.1.0"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.5.2"
14
+ end
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ command-builder (0.1.0)
5
+ hash-utils (>= 0.7.0)
6
+ git (1.2.5)
7
+ hash-utils (0.9.0)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ pipe-run (0.1.0)
13
+ rake (0.8.7)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.0.0)
20
+ command-builder (>= 0.1.0)
21
+ hash-utils (>= 0.9.0)
22
+ jeweler (~> 1.5.2)
23
+ pipe-run (>= 0.1.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ Unix Whereis
2
+ ============
3
+
4
+ **Unix Whereis** provides Ruby interface to UNIX `whereis` command.
5
+ Some examples follow: (for details, see module documentation)
6
+
7
+ require "unix/whereis"
8
+
9
+ Whereis.file? :ls
10
+ # will return ["/bin/ls", "/usr/share/man/man1/ls.1.gz", "/usr/share/man/man1/ls.1p.gz"]
11
+
12
+ Whereis.binary? :ls
13
+ # will return ["/bin/ls"]
14
+
15
+ Whereis.available? :ls
16
+ # will return true
17
+
18
+ Contributing
19
+ ------------
20
+
21
+ 1. Fork it.
22
+ 2. Create a branch (`git checkout -b 20101220-my-change`).
23
+ 3. Commit your changes (`git commit -am "Added something"`).
24
+ 4. Push to the branch (`git push origin 20101220-my-change`).
25
+ 5. Create an [Issue][2] with a link to your branch.
26
+ 6. Enjoy a refreshing Diet Coke and wait.
27
+
28
+ Copyright
29
+ ---------
30
+
31
+ Copyright © 2011 [Martin Kozák][3]. See `LICENSE.txt` for
32
+ further details.
33
+
34
+ [2]: http://github.com/martinkozak/qrpc/issues
35
+ [3]: http://www.martinkozak.net/
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "unix-whereis"
17
+ gem.homepage = "https://github.com/martinkozak/unix-whereis"
18
+ gem.license = "MIT"
19
+ gem.summary = "Ruby interface to UNIX 'whereis' command."
20
+ gem.email = "martinkozak@martinkozak.net"
21
+ gem.authors = ["Martin Kozák"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/rdoctask'
30
+ Rake::RDocTask.new do |rdoc|
31
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
32
+
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = "qrpc #{version}"
35
+ rdoc.rdoc_files.include('README*')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,220 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ require "command-builder"
5
+ require "pipe-run"
6
+ require "hash-utils/hash"
7
+
8
+ ##
9
+ # UNIX +whereis+ command frontend.
10
+ # @see
11
+ #
12
+
13
+ class Whereis
14
+
15
+ ##
16
+ # Target types to arguments conversion table.
17
+ #
18
+
19
+ TYPES = {
20
+ :binary => :b,
21
+ :manual => :m,
22
+ :source => :s,
23
+ :unusual => :u,
24
+ }
25
+
26
+ ##
27
+ # Target type path settings to arguments conversion table.
28
+ #
29
+
30
+ PATHS = {
31
+ :binary => :B,
32
+ :manual => :M,
33
+ :source => :S,
34
+ }
35
+
36
+ ##
37
+ # Checks where is some file. By default uses default
38
+ # whereis options.
39
+ #
40
+ # @overload file?(name, options = nil)
41
+ # Checks according to file name and single type specification.
42
+ # Can be replaced by specialized methods of the module which use
43
+ # it. Type specification can be +:binary+, +:manual+ or +:source+.
44
+ # @param [String] name name or wildcard of the file
45
+ # @param [Symbol] options type of the file
46
+ # @return [Array] list of found locations
47
+ #
48
+ # @overload file?(name, options = [ ])
49
+ # Allows define multiple types for checking with eventual addition
50
+ # of the +whereis+ "unusual" setting.
51
+ # @param [String] name name or wildcard of the file
52
+ # @param [Array] options array of type of the files and eventually the +:unusual+ specification
53
+ # @return [Array] list of found locations
54
+ # @see TYPES
55
+ #
56
+ # @overload file?(name, options = { })
57
+ # Allows define paths for each type and eventually the unusual
58
+ # settings too.
59
+ # @param [String] name name or wildcard of the file
60
+ # @param [Hash] options path specifications and/or +:unusual+ setting (see below)
61
+ # @option options [String] :binary path to binaries folder
62
+ # @option options [String] :manual path to manual pages folder
63
+ # @option options [String] :source path to sources folder
64
+ # @option options [Boolean] :unusual +true+ for set the "unusual" flag
65
+ # @return [Array] list of found locations
66
+ # @see PATHS
67
+ #
68
+ # @return [Array] list of found locations
69
+ #
70
+
71
+ def self.file?(name, options = [ ])
72
+
73
+ # Parses arguments
74
+ cmd = CommandBuilder::new(:whereis)
75
+
76
+ if options.kind_of? Symbol
77
+ __add_type(cmd, options)
78
+ elsif options.kind_of? Array
79
+ options.each { |i| __add_type(cmd, i) }
80
+ elsif options.kind_of? Hash
81
+ options.each_pair { |n, v| __add_path(cmd, n, v) }
82
+ end
83
+
84
+ cmd << name.to_s
85
+
86
+ # Parses output
87
+ output = Pipe.run(cmd.to_s)[(name.to_s.length + 2)..-1]
88
+ return output.split(" ")
89
+ end
90
+
91
+ ##
92
+ # Checks where is some binary file. By default uses default
93
+ # whereis options.
94
+ #
95
+ # @overload binary?(name, options = nil)
96
+ # Checks according to name and +:unusual+ settings.
97
+ # @param [String] name name or wildcard of the file
98
+ # @param [:unusual, nil] options eventuall +:unusual+ settings
99
+ # @return [Array] list of found locations
100
+ # @overload binary?(name, options = { })
101
+ # Checks according to name and additionaů options.
102
+ # @param [String] name name or wildcard of the file
103
+ # @param [Hash] options options
104
+ # @option options [String] :path path to binary folder
105
+ # @option options [Boolean] :unusual +true+ it it's set, +false+ in otherwise
106
+ # @return [Array] list of found locations
107
+ #
108
+ # @return [Array] list of found locations
109
+ #
110
+
111
+ def self.binary?(name, options = nil)
112
+ __get(name, :binary, options)
113
+ end
114
+
115
+ ##
116
+ # Checks where is some manual page file. By default uses default
117
+ # whereis options.
118
+ #
119
+ # @overload manual?(name, options = nil)
120
+ # Checks according to name and +:unusual+ settings.
121
+ # @param [String] name name or wildcard of the file
122
+ # @param [:unusual, nil] options eventuall +:unusual+ settings
123
+ # @return [Array] list of found locations
124
+ # @overload manual?(name, options = { })
125
+ # Checks according to name and additionaů options.
126
+ # @param [String] name name or wildcard of the file
127
+ # @param [Hash] options options
128
+ # @option options [String] :path path to manual pages folder
129
+ # @option options [Boolean] :unusual +true+ it it's set, +false+ in otherwise
130
+ # @return [Array] list of found locations
131
+ #
132
+ # @return [Array] list of found locations
133
+ #
134
+
135
+ def self.manual?(name, options = nil)
136
+ __get(name, :manual, options)
137
+ end
138
+
139
+ ##
140
+ # Checks where is some source file. By default uses default
141
+ # whereis options.
142
+ #
143
+ # @overload source?(name, options = nil)
144
+ # Checks according to name and +:unusual+ settings.
145
+ # @param [String] name name or wildcard of the file
146
+ # @param [:unusual, nil] options eventuall +:unusual+ settings
147
+ # @return [Array] list of found locations
148
+ # @overload source?(name, options = { })
149
+ # Checks according to name and additionaů options.
150
+ # @param [String] name name or wildcard of the file
151
+ # @param [Hash] options options
152
+ # @option options [String] :path path to source folder
153
+ # @option options [Boolean] :unusual +true+ it it's set, +false+ in otherwise
154
+ # @return [Array] list of found locations
155
+ #
156
+ # @return [Array] list of found locations
157
+ #
158
+
159
+ def self.source?(name, options = nil)
160
+ __get(name, :source, options)
161
+ end
162
+
163
+ ##
164
+ # Indicates, file of the target type is available.
165
+ #
166
+
167
+ def self.available?(name, type = :binary)
168
+ self.file?(name, type).length > 0
169
+ end
170
+
171
+
172
+
173
+ private
174
+
175
+ ##
176
+ # Translates type specific calls to general calls.
177
+ #
178
+
179
+ def self.__get(name, type, options = nil)
180
+ if options.kind_of? Hash
181
+ arg = { }
182
+ if options[:path]
183
+ arg[type] = options[:path]
184
+ end
185
+ if options[:unusual]
186
+ arg[:unusual] = options[:unusual]
187
+ end
188
+ elsif options == :unusual
189
+ arg = [type, :unusual]
190
+ elsif options.kind_of? NilClass
191
+ arg = type
192
+ else
193
+ raise Exception::new("Hash, Symbol or nil expected in options.")
194
+ end
195
+
196
+ self.file?(name, arg)
197
+ end
198
+
199
+ ##
200
+ # Adds type argument to command according to type specification.
201
+ #
202
+
203
+ def self.__add_type(cmd, type)
204
+ cmd << self::TYPES[type]
205
+ end
206
+
207
+ ##
208
+ # Adds path arguments to command according to type and
209
+ # paths specification.
210
+ #
211
+
212
+ def self.__add_path(cmd, type, path)
213
+ if type != :unusual
214
+ cmd.arg(self::PATHS[type], path)
215
+ end
216
+
217
+ __add_type(cmd, type)
218
+ end
219
+
220
+ end
data/test ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+
4
+ $:.push("./lib")
5
+ require "unix/whereis"
6
+
7
+ puts Whereis.available?(:jpegoptim).inspect
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{unix-whereis}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Martin Kozák"]
12
+ s.date = %q{2011-02-21}
13
+ s.email = %q{martinkozak@martinkozak.net}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/unix/whereis.rb",
27
+ "test",
28
+ "unix-whereis.gemspec"
29
+ ]
30
+ s.homepage = %q{https://github.com/martinkozak/unix-whereis}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.5.2}
34
+ s.summary = %q{Ruby interface to UNIX 'whereis' command.}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<hash-utils>, [">= 0.9.0"])
41
+ s.add_runtime_dependency(%q<pipe-run>, [">= 0.1.0"])
42
+ s.add_runtime_dependency(%q<command-builder>, [">= 0.1.0"])
43
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
44
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
45
+ else
46
+ s.add_dependency(%q<hash-utils>, [">= 0.9.0"])
47
+ s.add_dependency(%q<pipe-run>, [">= 0.1.0"])
48
+ s.add_dependency(%q<command-builder>, [">= 0.1.0"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<hash-utils>, [">= 0.9.0"])
54
+ s.add_dependency(%q<pipe-run>, [">= 0.1.0"])
55
+ s.add_dependency(%q<command-builder>, [">= 0.1.0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
58
+ end
59
+ end
60
+
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unix-whereis
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - "Martin Koz\xC3\xA1k"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-21 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: hash-utils
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: pipe-run
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.1.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: command-builder
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: jeweler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.5.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description:
72
+ email: martinkozak@martinkozak.net
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE.txt
79
+ - README.md
80
+ files:
81
+ - .document
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - VERSION
88
+ - lib/unix/whereis.rb
89
+ - test
90
+ - unix-whereis.gemspec
91
+ has_rdoc: true
92
+ homepage: https://github.com/martinkozak/unix-whereis
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 314693073242777781
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.5.2
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Ruby interface to UNIX 'whereis' command.
122
+ test_files: []
123
+