ruby-nuggets 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +1,4 @@
1
- #--
2
- ###############################################################################
3
- # #
4
- # A component of ruby-nuggets, some extensions to the Ruby programming #
5
- # language. #
6
- # #
7
- # Copyright (C) 2007-2011 Jens Wille #
8
- # #
9
- # Authors: #
10
- # Jens Wille <jens.wille@gmail.com> #
11
- # #
12
- # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
- # under the terms of the GNU Affero General Public License as published by #
14
- # the Free Software Foundation; either version 3 of the License, or (at your #
15
- # option) any later version. #
16
- # #
17
- # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
20
- # for more details. #
21
- # #
22
- # You should have received a copy of the GNU Affero General Public License #
23
- # along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
- # #
25
- ###############################################################################
26
- #++
1
+ require 'nuggets/pluggable'
2
+ module Util; Pluggable = ::Nuggets::Pluggable; end
27
3
 
28
- require 'set'
29
-
30
- module Util
31
-
32
- module Pluggable
33
-
34
- def self.load_plugins_for(*klasses)
35
- klasses.map { |klass| klass.extend(self).load_plugins }
36
- end
37
-
38
- def load_plugins(name = plugin_filename)
39
- load_path_plugins(name)
40
- load_gem_plugins(name)
41
- load_env_plugins(name)
42
-
43
- loaded_plugins.to_a
44
- end
45
-
46
- def loaded_plugins
47
- @loaded_plugins ||= Set.new
48
- end
49
-
50
- def plugin_filename
51
- @plugin_filename ||= "#{name.
52
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
53
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
54
- gsub(/::/, '/').tr('-', '_').downcase}_plugin.rb"
55
- end
56
-
57
- attr_writer :plugin_filename
58
-
59
- private
60
-
61
- def load_path_plugins(name)
62
- $LOAD_PATH.dup.each { |path|
63
- plugin = ::File.expand_path(name, path)
64
- load_plugin_file(plugin) if ::File.file?(plugin)
65
- }
66
- end
67
-
68
- def load_gem_plugins(name)
69
- ::Gem::Specification.latest_specs.each { |spec|
70
- load_plugin_files(spec.matches_for_glob(name))
71
- } if ::Object.const_defined?(:Gem)
72
- end
73
-
74
- def load_env_plugins(name)
75
- path = ::ENV["#{name.chomp(ext = ::File.extname(name)).upcase}_PATH"]
76
- path.split(::File::PATH_SEPARATOR).each { |dir|
77
- load_plugin_files(::Dir["#{dir}/*#{ext}"])
78
- } if path
79
- end
80
-
81
- def load_plugin_file(plugin)
82
- load plugin if loaded_plugins.add?(plugin)
83
- rescue ::Exception => err
84
- raise unless loaded_plugins.delete?(plugin)
85
- warn "Error loading #{name} plugin: #{plugin}: #{err} (#{err.class})"
86
- end
87
-
88
- def load_plugin_files(plugins)
89
- plugins.each { |plugin| load_plugin_file(::File.expand_path(plugin)) }
90
- end
91
-
92
- end
93
-
94
- end
4
+ warn "#{__FILE__}: Util::Pluggable is deprecated, use Nuggets::Pluggable instead."
@@ -1,348 +1,4 @@
1
- #--
2
- ###############################################################################
3
- # #
4
- # A component of ruby-nuggets, some extensions to the Ruby programming #
5
- # language. #
6
- # #
7
- # Copyright (C) 2007-2011 Jens Wille #
8
- # #
9
- # Authors: #
10
- # Jens Wille <jens.wille@gmail.com> #
11
- # #
12
- # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
- # under the terms of the GNU Affero General Public License as published by #
14
- # the Free Software Foundation; either version 3 of the License, or (at your #
15
- # option) any later version. #
16
- # #
17
- # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
20
- # for more details. #
21
- # #
22
- # You should have received a copy of the GNU Affero General Public License #
23
- # along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
- # #
25
- ###############################################################################
26
- #++
1
+ require 'nuggets/ruby'
2
+ module Util; Ruby = ::Nuggets::Ruby; end
27
3
 
28
- require 'rbconfig'
29
-
30
- module Util
31
-
32
- # Heavily based on Phusion Passenger's PlatformInfo module; see
33
- # {their code}[https://github.com/FooBarWidget/passenger/blob/release-3.0.2/lib/phusion_passenger/platform_info/ruby.rb].
34
- #
35
- #--
36
- # Phusion Passenger - http://www.modrails.com/
37
- # Copyright (c) 2010 Phusion
38
- #
39
- # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
40
- #
41
- # Permission is hereby granted, free of charge, to any person obtaining a
42
- # copy of this software and associated documentation files (the "Software"),
43
- # to deal in the Software without restriction, including without limitation
44
- # the rights to use, copy, modify, merge, publish, distribute, sublicense,
45
- # and/or sell copies of the Software, and to permit persons to whom the
46
- # Software is furnished to do so, subject to the following conditions:
47
- #
48
- # The above copyright notice and this permission notice shall be included in
49
- # all copies or substantial portions of the Software.
50
- #++
51
-
52
- module Ruby
53
-
54
- extend self
55
-
56
- CONFIG = ::RbConfig::CONFIG
57
-
58
- # Store original $GEM_HOME value so that even if the app customizes
59
- # $GEM_HOME we can still work with the original value.
60
- if gem_home = ::ENV['GEM_HOME']
61
- gem_home = gem_home.strip.freeze
62
- gem_home = nil if gem_home.empty?
63
- end
64
-
65
- GEM_HOME = gem_home
66
-
67
- RUBY_ENGINE = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'ruby'
68
-
69
- OSX_RUBY_RE = %r{\A/System/Library/Frameworks/Ruby.framework/Versions/.*?/usr/bin/ruby\Z}
70
-
71
- UPDATE_RVM = %q{Please update RVM by running 'rvm update --head && rvm reload && rvm repair all'.} # :nodoc:
72
-
73
- # Returns correct command for invoking the current Ruby interpreter.
74
- # In case of RVM this function will return the path to the RVM wrapper script
75
- # that executes the current Ruby interpreter in the currently active gem set.
76
- def ruby_command
77
- return @ruby_command if defined?(@ruby_command)
78
-
79
- return @ruby_command = ruby_executable unless rvm?
80
-
81
- if name = rvm_ruby_string and dir = rvm_path
82
- if ::File.exist?(filename = ::File.join(dir, 'wrappers', name, 'ruby'))
83
- # Old wrapper scripts reference $HOME which causes
84
- # things to blow up when run by a different user.
85
- return @ruby_command = filename unless ::File.read(filename).include?('$HOME')
86
- end
87
-
88
- abort 'Your RVM wrapper scripts are too old. ' << UPDATE_RVM
89
- end
90
-
91
- # Something's wrong with the user's RVM installation.
92
- # Raise an error so that the user knows this instead of
93
- # having things fail randomly later on.
94
- # 'name' is guaranteed to be non-nil because rvm_ruby_string
95
- # already raises an exception on error.
96
- abort 'Your RVM installation appears to be broken: the RVM path cannot be found. ' <<
97
- 'Please fix your RVM installation or contact the RVM developers for support.'
98
- end
99
-
100
- attr_writer :ruby_command
101
-
102
- # Returns the full path to the current Ruby interpreter's executable file.
103
- # This might not be the actual correct command to use for invoking the Ruby
104
- # interpreter; use ruby_command instead.
105
- def ruby_executable
106
- @ruby_executable ||= begin
107
- dir, name, ext = CONFIG.values_at(*%w[bindir RUBY_INSTALL_NAME EXEEXT])
108
- ::File.join(dir, name + ext).sub(/.*\s.*/m, '"\&"')
109
- end
110
- end
111
-
112
- attr_writer :ruby_executable
113
-
114
- # Returns whether the Ruby interpreter supports process forking.
115
- def ruby_supports_fork?
116
- # MRI >= 1.9.2's respond_to? returns false
117
- # for methods that are not implemented.
118
- ::Process.respond_to?(:fork) &&
119
- RUBY_ENGINE != 'jruby' &&
120
- RUBY_ENGINE != 'macruby' &&
121
- CONFIG['target_os'] !~ /mswin|windows|mingw/
122
- end
123
-
124
- # Returns whether the current Ruby interpreter is managed by RVM.
125
- def rvm?
126
- CONFIG['bindir'] =~ %r{/\.?rvm/}
127
- end
128
-
129
- # If the current Ruby interpreter is managed by RVM, returns the
130
- # directory in which RVM places its working files. Otherwise returns
131
- # +nil+.
132
- def rvm_path
133
- return @rvm_path if defined?(@rvm_path)
134
-
135
- return @rvm_path = nil unless rvm?
136
-
137
- [::ENV['rvm_path'], '~/.rvm', '/usr/local/rvm'].compact.each { |path|
138
- path = ::File.expand_path(path)
139
- return @rvm_path = path if ::File.directory?(path)
140
- }
141
-
142
- # Failure to locate the RVM path is probably caused by the
143
- # user customizing $rvm_path. Older RVM versions don't
144
- # export $rvm_path, making us unable to detect its value.
145
- abort 'Unable to locate the RVM path. Your RVM ' <<
146
- 'installation is probably too old. ' << UPDATE_RVM
147
- end
148
-
149
- attr_writer :rvm_path
150
-
151
- # If the current Ruby interpreter is managed by RVM, returns the
152
- # RVM name which identifies the current Ruby interpreter plus the
153
- # currently active gemset, e.g. something like this:
154
- # "ruby-1.9.2-p0@mygemset"
155
- #
156
- # Returns +nil+ otherwise.
157
- def rvm_ruby_string
158
- return @rvm_ruby_string if defined?(@rvm_ruby_string)
159
-
160
- return @rvm_ruby_string = nil unless rvm?
161
-
162
- # RVM used to export the necessary information through
163
- # environment variables, but doesn't always do that anymore
164
- # in the latest versions in order to fight env var pollution.
165
- # Scanning $LOAD_PATH seems to be the only way to obtain
166
- # the information.
167
-
168
- # Getting the RVM name of the Ruby interpreter ("ruby-1.9.2")
169
- # isn't so hard, we can extract it from the #ruby_executable
170
- # string. Getting the gemset name is a bit harder, so let's
171
- # try various strategies...
172
-
173
- # $GEM_HOME usually contains the gem set name.
174
- return @rvm_ruby_string = ::File.basename(GEM_HOME) if GEM_HOME && GEM_HOME.include?('rvm/gems/')
175
-
176
- # User somehow managed to nuke $GEM_HOME. Extract info from $LOAD_PATH.
177
- $LOAD_PATH.each { |path| return @rvm_ruby_string = $1 if path =~ %r{^.*rvm/gems/([^/]+)} }
178
-
179
- # On Ruby 1.9, $LOAD_PATH does not contain any gem paths until
180
- # at least one gem has been required so the above can fail.
181
- # We're out of options now, we can't detect the gem set.
182
- # Raise an exception so that the user knows what's going on
183
- # instead of having things fail in obscure ways later.
184
- abort 'Unable to autodetect the currently active RVM gem set ' <<
185
- "name. Please contact this program's author for support."
186
- end
187
-
188
- attr_writer :rvm_ruby_string
189
-
190
- # Returns either 'sudo' or 'rvmsudo' depending on whether the current
191
- # Ruby interpreter is managed by RVM.
192
- def ruby_sudo_command
193
- "#{'rvm' if rvm?}sudo"
194
- end
195
-
196
- # Locates a Ruby tool command +name+, e.g. 'gem', 'rake', 'bundle', etc. Instead
197
- # of naively looking in $PATH, this function uses a variety of search heuristics
198
- # to find the command that's really associated with the current Ruby interpreter.
199
- # It should never locate a command that's actually associated with a different
200
- # Ruby interpreter.
201
- #
202
- # NOTE: The return value may not be the actual correct invocation for the tool.
203
- # Use command_for_ruby_tool for that.
204
- #
205
- # Returns +nil+ when nothing's found.
206
- def locate_ruby_tool(name)
207
- extensions = ['', CONFIG['EXEEXT']].compact.uniq
208
-
209
- # Deduce Ruby's --program-prefix and --program-suffix from its install name
210
- # and transform the given input name accordingly.
211
- #
212
- # "rake" => "jrake", "rake1.8", etc
213
- [name, CONFIG['RUBY_INSTALL_NAME'].sub('ruby', name)].uniq.each { |basename|
214
- extensions.each { |ext|
215
- result = locate_ruby_tool_by_basename("#{basename}#{ext}")
216
- return result if result
217
- }
218
- }
219
-
220
- nil
221
- end
222
-
223
- # Returns the correct command string for invoking the +name+ executable
224
- # that belongs to the current Ruby interpreter. Returns +nil+ if the
225
- # command is not found.
226
- #
227
- # If the command executable is a Ruby program, then we need to run it
228
- # in the correct Ruby interpreter just in case the command doesn't
229
- # have the correct shebang line; we don't want a totally different
230
- # Ruby than the current one to be invoked.
231
- #
232
- # If it's not a Ruby program then it's probably a wrapper
233
- # script as is the case with e.g. RVM (~/.rvm/wrappers).
234
- def command_for_ruby_tool(name)
235
- filename = respond_to?(name) ? send(name) : locate_ruby_tool(name)
236
- shebang_command(filename) =~ /ruby/ ? "#{ruby_command} #{filename}" : filename
237
- end
238
-
239
- %w[gem rake rspec].each { |name|
240
- class_eval <<-EOT, __FILE__, __LINE__ + 1
241
- def #{name}
242
- @#{name} ||= locate_ruby_tool('#{name}')
243
- end
244
-
245
- attr_writer :#{name}
246
-
247
- def #{name}_command
248
- @#{name}_command ||= command_for_ruby_tool('#{name}')
249
- end
250
-
251
- attr_writer :#{name}_command
252
- EOT
253
- }
254
-
255
- def ruby_options_to_argv(args, ruby_command = ruby_command)
256
- argv = [ruby_command]
257
-
258
- args.pop.each { |key, val|
259
- opt = "-#{key.to_s[0, 1]}"
260
-
261
- if val.is_a?(::Array)
262
- val.each { |wal|
263
- argv << opt << wal.to_s
264
- }
265
- else
266
- if opt == '-e'
267
- argv << opt << val.to_s
268
- elsif val != false
269
- argv << "#{opt}#{val unless val == true}"
270
- end
271
- end
272
- } if args.last.is_a?(::Hash)
273
-
274
- argv.concat(args.map! { |arg| arg.to_s.strip })
275
- end
276
-
277
- private
278
-
279
- def locate_ruby_tool_by_basename(name)
280
- dir = if ::RUBY_PLATFORM =~ /darwin/ && ruby_command =~ OSX_RUBY_RE
281
- # On OS X we must look for Ruby binaries in /usr/bin.
282
- # RubyGems puts executables (e.g. 'rake') in there, not in
283
- # /System/Libraries/(...)/bin.
284
- '/usr/bin'
285
- else
286
- ::File.dirname(ruby_command)
287
- end
288
-
289
- filename = ::File.join(dir, name)
290
- return filename if ::File.file?(filename) && ::File.executable?(filename)
291
-
292
- # RubyGems might put binaries in a directory other
293
- # than Ruby's bindir. Debian packaged RubyGems and
294
- # DebGem packaged RubyGems are the prime examples.
295
- begin
296
- require 'rubygems' unless defined?(::Gem)
297
-
298
- filename = ::File.join(::Gem.bindir, name)
299
- return filename if ::File.file?(filename) && ::File.executable?(filename)
300
- rescue ::LoadError
301
- end
302
-
303
- # Looks like it's not in the RubyGems bindir. Search in $PATH, but
304
- # be very careful about this because whatever we find might belong
305
- # to a different Ruby interpreter than the current one.
306
- ::ENV['PATH'].split(::File::PATH_SEPARATOR).each { |path|
307
- filename = ::File.join(path, name)
308
-
309
- if ::File.file?(filename) && ::File.executable?(filename)
310
- return filename if shebang_command(filename) == ruby_command
311
- end
312
- }
313
-
314
- nil
315
- end
316
-
317
- def shebang_command(filename)
318
- ::File.foreach(filename) { |line|
319
- return $1 if line =~ /\A#!\s*(\S*)/
320
-
321
- # Allow one extra line for magic comment.
322
- break if $. > 1
323
- }
324
- end
325
-
326
- end
327
-
328
- end
329
-
330
- def File.ruby; ::Util::Ruby.ruby_command; end
331
-
332
- begin
333
- require 'open4'
334
-
335
- def Process.ruby(*args)
336
- argv = ::Util::Ruby.ruby_options_to_argv(args)
337
- ::Open4.popen4(*argv, &block_given? ? ::Proc.new : nil)
338
- end
339
-
340
- require 'nuggets/io/interact'
341
-
342
- def Process.interact_ruby(input, *args)
343
- ruby(*args) { |_, i, o, e|
344
- ::IO.interact({ input => i }, { o => $stdout, e => $stderr })
345
- }
346
- end
347
- rescue ::LoadError
348
- end
4
+ warn "#{__FILE__}: Util::Ruby is deprecated, use Nuggets::Ruby instead."
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 9
7
- TINY = 1
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-12 00:00:00.000000000 Z
11
+ date: 2013-04-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Some extensions to the Ruby programming language.
14
14
  email: jens.wille@gmail.com
@@ -22,6 +22,7 @@ files:
22
22
  - lib/nuggets.rb
23
23
  - lib/nuggets/all.rb
24
24
  - lib/nuggets/all_mixins.rb
25
+ - lib/nuggets/ansicolor2css.rb
25
26
  - lib/nuggets/array/boost.rb
26
27
  - lib/nuggets/array/boost_mixin.rb
27
28
  - lib/nuggets/array/combination.rb
@@ -53,6 +54,9 @@ files:
53
54
  - lib/nuggets/array/to_hash.rb
54
55
  - lib/nuggets/array/variance.rb
55
56
  - lib/nuggets/array/variance_mixin.rb
57
+ - lib/nuggets/cli.rb
58
+ - lib/nuggets/content_type.rb
59
+ - lib/nuggets/dotted_decimal.rb
56
60
  - lib/nuggets/enumerable/agrep.rb
57
61
  - lib/nuggets/enumerable/all_any_extended.rb
58
62
  - lib/nuggets/enumerable/minmax.rb
@@ -82,6 +86,7 @@ files:
82
86
  - lib/nuggets/hash/seen_mixin.rb
83
87
  - lib/nuggets/hash/unroll.rb
84
88
  - lib/nuggets/hash/unroll_mixin.rb
89
+ - lib/nuggets/i18n.rb
85
90
  - lib/nuggets/integer/factorial.rb
86
91
  - lib/nuggets/integer/length.rb
87
92
  - lib/nuggets/integer/length_mixin.rb
@@ -96,6 +101,12 @@ files:
96
101
  - lib/nuggets/io/null_mixin.rb
97
102
  - lib/nuggets/io/redirect.rb
98
103
  - lib/nuggets/io/redirect_mixin.rb
104
+ - lib/nuggets/lazy_attr.rb
105
+ - lib/nuggets/log_parser.rb
106
+ - lib/nuggets/log_parser/apache.rb
107
+ - lib/nuggets/log_parser/rails.rb
108
+ - lib/nuggets/midos.rb
109
+ - lib/nuggets/mysql.rb
99
110
  - lib/nuggets/net/success.rb
100
111
  - lib/nuggets/numeric/between.rb
101
112
  - lib/nuggets/numeric/duration.rb
@@ -117,10 +128,12 @@ files:
117
128
  - lib/nuggets/object/singleton_class_mixin.rb
118
129
  - lib/nuggets/object/uniclass.rb
119
130
  - lib/nuggets/object/virtual_class.rb
131
+ - lib/nuggets/pluggable.rb
120
132
  - lib/nuggets/proc/bind.rb
121
133
  - lib/nuggets/proc/bind_mixin.rb
122
134
  - lib/nuggets/range/quantile.rb
123
135
  - lib/nuggets/range/quantile_mixin.rb
136
+ - lib/nuggets/ruby.rb
124
137
  - lib/nuggets/statistics.rb
125
138
  - lib/nuggets/statistics_mixins.rb
126
139
  - lib/nuggets/string/camelscore.rb
@@ -144,8 +157,6 @@ files:
144
157
  - lib/nuggets/uri/exist_mixin.rb
145
158
  - lib/nuggets/uri/redirect.rb
146
159
  - lib/nuggets/uri/redirect_mixin.rb
147
- - lib/nuggets/util/added_methods.rb
148
- - lib/nuggets/util/added_methods/init.rb
149
160
  - lib/nuggets/util/ansicolor2css.rb
150
161
  - lib/nuggets/util/cli.rb
151
162
  - lib/nuggets/util/content_type.rb
@@ -155,6 +166,7 @@ files:
155
166
  - lib/nuggets/util/log_parser.rb
156
167
  - lib/nuggets/util/log_parser/apache.rb
157
168
  - lib/nuggets/util/log_parser/rails.rb
169
+ - lib/nuggets/util/midos.rb
158
170
  - lib/nuggets/util/mysql.rb
159
171
  - lib/nuggets/util/pluggable.rb
160
172
  - lib/nuggets/util/ruby.rb
@@ -202,7 +214,7 @@ files:
202
214
  - spec/nuggets/uri/exist_spec.rb
203
215
  - spec/spec_helper.rb
204
216
  - .rspec
205
- homepage: http://prometheus.rubyforge.org/ruby-nuggets
217
+ homepage: http://github.com/blackwinter/ruby-nuggets
206
218
  licenses: []
207
219
  metadata: {}
208
220
  post_install_message:
@@ -212,7 +224,7 @@ rdoc_options:
212
224
  - --line-numbers
213
225
  - --all
214
226
  - --title
215
- - ruby-nuggets Application documentation (v0.9.1)
227
+ - ruby-nuggets Application documentation (v0.9.2)
216
228
  - --main
217
229
  - README
218
230
  require_paths:
@@ -228,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
240
  - !ruby/object:Gem::Version
229
241
  version: '0'
230
242
  requirements: []
231
- rubyforge_project: prometheus
243
+ rubyforge_project:
232
244
  rubygems_version: 2.0.3
233
245
  signing_key:
234
246
  specification_version: 4
@@ -1,3 +0,0 @@
1
- # just a short-cut
2
- require 'nuggets/util/added_methods'
3
- Util::AddedMethods.init
@@ -1,6 +0,0 @@
1
- # backwards compatibility
2
- require 'added_methods'
3
-
4
- module Util
5
- AddedMethods = ::AddedMethods
6
- end