ruby-nuggets 0.8.0 → 0.8.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.
data/.rspec CHANGED
@@ -1,3 +1 @@
1
1
  --colour
2
- --debug
3
- --require spec/spec_helper
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.8.0
5
+ This documentation refers to ruby-nuggets version 0.8.1
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -119,6 +119,13 @@ module Nuggets
119
119
  buffer << reader.read_nonblock(maxlen)
120
120
  rescue ::Errno::EAGAIN
121
121
  rescue ::EOFError
122
+ buffer.force_encoding(
123
+ reader.internal_encoding ||
124
+ reader.external_encoding ||
125
+ Encoding.default_internal ||
126
+ Encoding.default_external
127
+ ) if buffer.respond_to?(:force_encoding)
128
+
122
129
  close[container, writer || reader, !writer]
123
130
  end
124
131
  }
@@ -133,12 +140,15 @@ module Nuggets
133
140
  read[reader, buffer, writer] or next if buffer.empty?
134
141
 
135
142
  begin
136
- written = writer.write_nonblock(buffer)
143
+ bytes = writer.write_nonblock(buffer)
137
144
  rescue ::Errno::EPIPE
138
145
  close[writers, writer]
139
146
  end
140
147
 
141
- buffer.slice!(0, written) if written
148
+ if bytes
149
+ buffer.force_encoding('BINARY') if buffer.respond_to?(:force_encoding)
150
+ buffer.slice!(0, bytes)
151
+ end
142
152
  }
143
153
  end
144
154
 
@@ -61,7 +61,7 @@ module Util
61
61
  return mod.const_get(const) if mod.const_defined?(const)
62
62
  }
63
63
 
64
- raise NameError, "uninitialized constant #{self}::#{const}"
64
+ raise ::NameError, "uninitialized constant #{self}::#{const}"
65
65
  end
66
66
 
67
67
  end
@@ -162,7 +162,7 @@ module Util
162
162
  end
163
163
 
164
164
  def merge_config(args = [config, defaults])
165
- args.each { |hash| hash.each { |key, value|
165
+ args.each { |hash| hash && hash.each { |key, value|
166
166
  options[key] = value unless options.has_key?(key)
167
167
  } }
168
168
  end
@@ -0,0 +1,83 @@
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@uni-koeln.de> #
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
+ #++
27
+
28
+ module Util
29
+
30
+ module Pluggable
31
+
32
+ class << self
33
+
34
+ def load_plugins_for(*klasses)
35
+ klasses.map { |klass| klass.extend(self).load_plugins }
36
+ end
37
+
38
+ def extended(base)
39
+ base.plugin_filename ||= "#{base.name.
40
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
41
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
42
+ gsub(/::/, '/').tr('-', '_').downcase}_plugin.rb"
43
+ end
44
+
45
+ end
46
+
47
+ attr_accessor :plugin_filename
48
+
49
+ def load_plugins
50
+ plugins, name = [], plugin_filename
51
+ plugins.concat(load_env_plugins(name))
52
+ plugins.concat(load_gem_plugins(name)) if defined?(::Gem)
53
+ plugins
54
+ end
55
+
56
+ private
57
+
58
+ def load_env_plugins(name)
59
+ load_plugin_files($LOAD_PATH.map { |path|
60
+ plugin = ::File.expand_path(name, path)
61
+ plugin if ::File.file?(plugin)
62
+ }.compact)
63
+ end
64
+
65
+ def load_gem_plugins(name)
66
+ load_plugin_files(::Gem::Specification.map { |spec|
67
+ spec.matches_for_glob(name)
68
+ }.flatten)
69
+ end
70
+
71
+ def load_plugin_files(plugins)
72
+ plugins.each { |plugin|
73
+ begin
74
+ load plugin
75
+ rescue ::Exception => err
76
+ warn "Error loading #{name} plugin: #{plugin}: #{err} (#{err.class})"
77
+ end
78
+ }
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -97,6 +97,8 @@ module Util
97
97
  'Please fix your RVM installation or contact the RVM developers for support.'
98
98
  end
99
99
 
100
+ attr_writer :ruby_command
101
+
100
102
  # Returns the full path to the current Ruby interpreter's executable file.
101
103
  # This might not be the actual correct command to use for invoking the Ruby
102
104
  # interpreter; use ruby_command instead.
@@ -107,6 +109,8 @@ module Util
107
109
  end
108
110
  end
109
111
 
112
+ attr_writer :ruby_executable
113
+
110
114
  # Returns whether the Ruby interpreter supports process forking.
111
115
  def ruby_supports_fork?
112
116
  # MRI >= 1.9.2's respond_to? returns false
@@ -142,6 +146,8 @@ module Util
142
146
  'installation is probably too old. ' << UPDATE_RVM
143
147
  end
144
148
 
149
+ attr_writer :rvm_path
150
+
145
151
  # If the current Ruby interpreter is managed by RVM, returns the
146
152
  # RVM name which identifies the current Ruby interpreter plus the
147
153
  # currently active gemset, e.g. something like this:
@@ -179,6 +185,8 @@ module Util
179
185
  "name. Please contact this program's author for support."
180
186
  end
181
187
 
188
+ attr_writer :rvm_ruby_string
189
+
182
190
  # Returns either 'sudo' or 'rvmsudo' depending on whether the current
183
191
  # Ruby interpreter is managed by RVM.
184
192
  def ruby_sudo_command
@@ -234,9 +242,13 @@ module Util
234
242
  @#{name} ||= locate_ruby_tool('#{name}')
235
243
  end
236
244
 
245
+ attr_writer :#{name}
246
+
237
247
  def #{name}_command
238
248
  @#{name}_command ||= command_for_ruby_tool('#{name}')
239
249
  end
250
+
251
+ attr_writer :#{name}_command
240
252
  EOT
241
253
  }
242
254
 
@@ -321,16 +333,15 @@ begin
321
333
  require 'open4'
322
334
 
323
335
  def Process.ruby(*args)
324
- argv = ::Util::Ruby.ruby_options_to_argv(args, ::File.ruby)
336
+ argv = ::Util::Ruby.ruby_options_to_argv(args)
325
337
  ::Open4.popen4(*argv, &block_given? ? ::Proc.new : nil)
326
338
  end
327
339
 
328
340
  require 'nuggets/io/interact'
329
341
 
330
342
  def Process.interact_ruby(input, *args)
331
- ruby(*args) { |p, i, o, e|
343
+ ruby(*args) { |_, i, o, e|
332
344
  ::IO.interact({ input => i }, { o => $stdout, e => $stderr })
333
- p
334
345
  }
335
346
  end
336
347
  rescue ::LoadError
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 8
7
- TINY = 0
7
+ TINY = 1
8
8
 
9
9
  class << self
10
10
 
@@ -67,7 +67,7 @@ describe Array, 'when extended by', Nuggets::Array::HistogramMixin do
67
67
  end
68
68
 
69
69
  example do
70
- [1, -2, 1, 2, 3, -4, 0, 3, 1, 2, 1, 0, 24].probability_mass_function.values.inject(:+).should == 1.0
70
+ [1, -2, 1, 2, 3, -4, 0, 3, 1, 2, 1, 0, 24].probability_mass_function.values.inject(:+).should equal_float(1.0)
71
71
  end
72
72
 
73
73
  example do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-13 00:00:00 Z
18
+ date: 2011-12-28 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Some extensions to the Ruby programming language.
@@ -135,6 +135,7 @@ files:
135
135
  - lib/nuggets/util/cli.rb
136
136
  - lib/nuggets/util/i18n.rb
137
137
  - lib/nuggets/util/added_methods/init.rb
138
+ - lib/nuggets/util/pluggable.rb
138
139
  - lib/nuggets/proc/bind_mixin.rb
139
140
  - lib/nuggets/proc/bind.rb
140
141
  - lib/nuggets/statistics.rb
@@ -203,7 +204,7 @@ rdoc_options:
203
204
  - --charset
204
205
  - UTF-8
205
206
  - --title
206
- - ruby-nuggets Application documentation (v0.8.0)
207
+ - ruby-nuggets Application documentation (v0.8.1)
207
208
  - --line-numbers
208
209
  require_paths:
209
210
  - lib
@@ -228,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
229
  requirements: []
229
230
 
230
231
  rubyforge_project: prometheus
231
- rubygems_version: 1.8.12
232
+ rubygems_version: 1.8.13
232
233
  signing_key:
233
234
  specification_version: 3
234
235
  summary: Some extensions to the Ruby programming language.