threadify 1.3.0 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDM2ZGI2N2E2ZWFjMGUwOGE5Mzg5ZGEzNTA0ZTFiY2JlMjU5Yjg0Ng==
5
+ data.tar.gz: !binary |-
6
+ Y2RlNjMyYWI2MGVhODExNDdiM2VhOTViOTUyOWViMmRlZGFjOWU2YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MTdlZWZhNGZlMmEyZDA5N2JhMjQ5MTA0MWRmNzZhZDMyMmM5YTE4MmJmZmI5
10
+ MmIxZWUzMjcyOGU4NjRhNzUzNDQ2MTlhZTM5NDQzN2M4ZjFmNzc1YTQxOWI5
11
+ Zjk4MGQ5N2YwMWEwMzY0YzY3NjllMDhiZjlkYTQyZDI5NDIzYjc=
12
+ data.tar.gz: !binary |-
13
+ ZGI5N2VmNWY2MGFkMzVlNGI2MGZmNTEyZDZhODYxODg1OWIzMzNjZjBkODc2
14
+ M2U1NjFhMDQ3MWZkNzIyNzVkMzIzMjI3ODc3MTFiMDkzZjI2MWQzZGZjNDAz
15
+ NWYwN2YyNjRiYzAzYzQwYmQwODlhODc3MDExYzQyNzFjOTJlYzE=
data/README CHANGED
@@ -64,9 +64,9 @@ SAMPLES
64
64
  ~ > ruby sample/a.rb
65
65
 
66
66
  ---
67
- without threadify: 10.1121168136597
67
+ without threadify: 8.49043202400208
68
68
  ---
69
- with threadify: 8.11967301368713
69
+ with threadify: 2.45102596282959
70
70
 
71
71
 
72
72
  <========< sample/b.rb >========>
@@ -118,9 +118,9 @@ SAMPLES
118
118
  ~ > ruby sample/b.rb
119
119
 
120
120
  ---
121
- without threadify: 20.6975500583649
121
+ without threadify: 19.2692859172821
122
122
  ---
123
- with threadify: 0.923933982849121
123
+ with threadify: 0.851074934005737
124
124
  ---
125
125
  :needle: 42
126
126
  :a: 42
@@ -130,6 +130,9 @@ SAMPLES
130
130
 
131
131
 
132
132
  HISTORY
133
+ 1.4.2
134
+ - fix name collision running under jruby's native threads. thanks charles nutter!
135
+
133
136
  1.3.0
134
137
  - added Threadify(*args, &block) method to execute arbitrary code in parallel
135
138
 
data/README.erb CHANGED
@@ -22,6 +22,9 @@ SAMPLES
22
22
 
23
23
 
24
24
  HISTORY
25
+ 1.4.2
26
+ - fix name collision running under jruby's native threads. thanks charles nutter!
27
+
25
28
  1.3.0
26
29
  - added Threadify(*args, &block) method to execute arbitrary code in parallel
27
30
 
@@ -1,7 +1,11 @@
1
1
  module Threadify
2
- Threadify::VERSION = '1.3.0' unless defined?(Threadify::VERSION)
2
+ Threadify::VERSION = '1.4.3' unless defined?(Threadify::VERSION)
3
3
  def Threadify.version() Threadify::VERSION end
4
4
 
5
+ def Threadify.description
6
+ 'https://github.com/ahoward/threadify.git'
7
+ end
8
+
5
9
  require 'thread'
6
10
  require 'enumerator'
7
11
 
@@ -90,8 +94,8 @@ module Enumerable
90
94
  break if caught
91
95
  job = jobsi.shift
92
96
  break if job == done
93
- args = job.first
94
- jobsi << (job << block.call(*args))
97
+ argv = job.first
98
+ jobsi << (job << block.call(*argv))
95
99
  }
96
100
  nothing
97
101
  end
@@ -99,7 +103,7 @@ module Enumerable
99
103
 
100
104
  unless nothing == thrown
101
105
  thrownq.push [i, thrown]
102
- args, i = job
106
+ argv, i = job
103
107
  end
104
108
  end
105
109
  end
data/rakefile CHANGED
@@ -1,18 +1,69 @@
1
-
2
1
  This.rubyforge_project = 'codeforpeople'
3
2
  This.author = "Ara T. Howard"
4
3
  This.email = "ara.t.howard@gmail.com"
5
- This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
4
+ This.homepage = "https://github.com/ahoward/#{ This.lib }"
6
5
 
6
+ task :license do
7
+ open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"}
8
+ end
7
9
 
8
10
  task :default do
9
- puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
11
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
12
+ end
13
+
14
+ task :test do
15
+ run_tests!
16
+ end
17
+
18
+ namespace :test do
19
+ task(:unit){ run_tests!(:unit) }
20
+ task(:functional){ run_tests!(:functional) }
21
+ task(:integration){ run_tests!(:integration) }
22
+ end
23
+
24
+ def run_tests!(which = nil)
25
+ which ||= '**'
26
+ test_dir = File.join(This.dir, "test")
27
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
28
+ test_rbs = Dir.glob(test_glob).sort
29
+
30
+ div = ('=' * 119)
31
+ line = ('-' * 119)
32
+
33
+ test_rbs.each_with_index do |test_rb, index|
34
+ testno = index + 1
35
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
36
+
37
+ puts
38
+ say(div, :color => :cyan, :bold => true)
39
+ say("@#{ testno } => ", :bold => true, :method => :print)
40
+ say(command, :color => :cyan, :bold => true)
41
+ say(line, :color => :cyan, :bold => true)
42
+
43
+ system(command)
44
+
45
+ say(line, :color => :cyan, :bold => true)
46
+
47
+ status = $?.exitstatus
48
+
49
+ if status.zero?
50
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
51
+ say("SUCCESS", :color => :green, :bold => true)
52
+ else
53
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
54
+ say("FAILURE", :color => :red, :bold => true)
55
+ end
56
+ say(line, :color => :cyan, :bold => true)
57
+
58
+ exit(status) unless status.zero?
59
+ end
10
60
  end
11
61
 
12
62
 
13
63
  task :gemspec do
14
- ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
15
- ignore_directories = 'pkg'
64
+ ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
65
+ ignore_directories = ['pkg']
66
+ ignore_files = ['test/log']
16
67
 
17
68
  shiteless =
18
69
  lambda do |list|
@@ -26,17 +77,27 @@ task :gemspec do
26
77
  dirname = File.expand_path(entry)
27
78
  ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
28
79
  end
80
+ list.delete_if do |entry|
81
+ next unless test(?f, entry)
82
+ filename = File.expand_path(entry)
83
+ ignore_files.any?{|file| File.expand_path(file) == filename}
84
+ end
29
85
  end
30
86
 
31
87
  lib = This.lib
88
+ object = This.object
32
89
  version = This.version
33
90
  files = shiteless[Dir::glob("**/**")]
34
91
  executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
35
- has_rdoc = true #File.exist?('doc')
92
+ #has_rdoc = true #File.exist?('doc')
36
93
  test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
94
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
95
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
96
+ license = object.respond_to?(:license) ? object.license : "same as ruby's"
37
97
 
38
- extensions = This.extensions
39
- if extensions.nil?
98
+ if This.extensions.nil?
99
+ This.extensions = []
100
+ extensions = This.extensions
40
101
  %w( Makefile configure extconf.rb ).each do |ext|
41
102
  extensions << ext if File.exists?(ext)
42
103
  end
@@ -57,16 +118,18 @@ task :gemspec do
57
118
  spec.version = #{ version.inspect }
58
119
  spec.platform = Gem::Platform::RUBY
59
120
  spec.summary = #{ lib.inspect }
121
+ spec.description = #{ description.inspect }
122
+ spec.license = #{ license.inspect }
60
123
 
61
- spec.files = #{ files.inspect }
124
+ spec.files =\n#{ files.sort.pretty_inspect }
62
125
  spec.executables = #{ executables.inspect }
63
126
 
64
127
  spec.require_path = "lib"
65
128
 
66
- spec.has_rdoc = #{ has_rdoc.inspect }
67
129
  spec.test_files = #{ test_files.inspect }
68
- #spec.add_dependency 'lib', '>= version'
69
- #spec.add_dependency 'fattr'
130
+
131
+ ### spec.add_dependency 'lib', '>= version'
132
+ #### spec.add_dependency 'map'
70
133
 
71
134
  spec.extensions.push(*#{ extensions.inspect })
72
135
 
@@ -79,19 +142,21 @@ task :gemspec do
79
142
  }
80
143
  end
81
144
 
82
- open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
83
- This.gemspec = "#{ lib }.gemspec"
145
+ Fu.mkdir_p(This.pkgdir)
146
+ gemspec = "#{ lib }.gemspec"
147
+ open(gemspec, "w"){|fd| fd.puts(template)}
148
+ This.gemspec = gemspec
84
149
  end
85
150
 
86
151
  task :gem => [:clean, :gemspec] do
87
- Fu.mkdir_p This.pkgdir
152
+ Fu.mkdir_p(This.pkgdir)
88
153
  before = Dir['*.gem']
89
154
  cmd = "gem build #{ This.gemspec }"
90
155
  `#{ cmd }`
91
156
  after = Dir['*.gem']
92
157
  gem = ((after - before).first || after.first) or abort('no gem!')
93
- Fu.mv gem, This.pkgdir
94
- This.gem = File.basename(gem)
158
+ Fu.mv(gem, This.pkgdir)
159
+ This.gem = File.join(This.pkgdir, File.basename(gem))
95
160
  end
96
161
 
97
162
  task :readme do
@@ -110,13 +175,13 @@ task :readme do
110
175
  cmd = "ruby #{ sample }"
111
176
  samples << Util.indent(prompt + cmd, 2) << "\n\n"
112
177
 
113
- cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
178
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
114
179
  samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
115
180
  end
116
181
 
117
182
  template =
118
- if test(?e, 'readme.erb')
119
- Template{ IO.read('readme.erb') }
183
+ if test(?e, 'README.erb')
184
+ Template{ IO.read('README.erb') }
120
185
  else
121
186
  Template {
122
187
  <<-__
@@ -147,9 +212,18 @@ task :release => [:clean, :gemspec, :gem] do
147
212
  gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
148
213
  raise "which one? : #{ gems.inspect }" if gems.size > 1
149
214
  raise "no gems?" if gems.size < 1
150
- cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
215
+
216
+ cmd = "gem push #{ This.gem }"
217
+ puts cmd
218
+ puts
219
+ system(cmd)
220
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
221
+
222
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
151
223
  puts cmd
152
- system cmd
224
+ puts
225
+ system(cmd)
226
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
153
227
  end
154
228
 
155
229
 
@@ -157,37 +231,63 @@ end
157
231
 
158
232
 
159
233
  BEGIN {
234
+ # support for this rakefile
235
+ #
160
236
  $VERBOSE = nil
161
237
 
162
238
  require 'ostruct'
163
239
  require 'erb'
164
240
  require 'fileutils'
241
+ require 'rbconfig'
242
+ require 'pp'
165
243
 
244
+ # fu shortcut
245
+ #
166
246
  Fu = FileUtils
167
247
 
248
+ # cache a bunch of stuff about this rakefile/environment
249
+ #
168
250
  This = OpenStruct.new
169
251
 
170
252
  This.file = File.expand_path(__FILE__)
171
253
  This.dir = File.dirname(This.file)
172
254
  This.pkgdir = File.join(This.dir, 'pkg')
173
255
 
256
+ # grok lib
257
+ #
174
258
  lib = ENV['LIB']
175
259
  unless lib
176
- lib = File.basename(Dir.pwd)
260
+ lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
177
261
  end
178
262
  This.lib = lib
179
263
 
264
+ # grok version
265
+ #
180
266
  version = ENV['VERSION']
181
267
  unless version
182
- name = lib.capitalize
183
- require "./lib/#{ lib }"
184
- version = eval(name).send(:version)
268
+ require "./lib/#{ This.lib }"
269
+ This.name = lib.capitalize
270
+ This.object = eval(This.name)
271
+ version = This.object.send(:version)
185
272
  end
186
273
  This.version = version
187
274
 
275
+ # we need to know the name of the lib an it's version
276
+ #
188
277
  abort('no lib') unless This.lib
189
278
  abort('no version') unless This.version
190
279
 
280
+ # discover full path to this ruby executable
281
+ #
282
+ c = Config::CONFIG
283
+ bindir = c["bindir"] || c['BINDIR']
284
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
285
+ ruby_ext = c['EXEEXT'] || ''
286
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
287
+ This.ruby = ruby
288
+
289
+ # some utils
290
+ #
191
291
  module Util
192
292
  def indent(s, n = 2)
193
293
  s = unindent(s)
@@ -197,7 +297,7 @@ BEGIN {
197
297
 
198
298
  def unindent(s)
199
299
  indent = nil
200
- s.each do |line|
300
+ s.each_line do |line|
201
301
  next if line =~ %r/^\s*$/
202
302
  indent = line[%r/^\s*/] and break
203
303
  end
@@ -206,17 +306,71 @@ BEGIN {
206
306
  extend self
207
307
  end
208
308
 
309
+ # template support
310
+ #
209
311
  class Template
210
312
  def initialize(&block)
211
313
  @block = block
212
314
  @template = block.call.to_s
213
315
  end
214
316
  def expand(b=nil)
215
- ERB.new(Util.unindent(@template)).result(b||@block)
317
+ ERB.new(Util.unindent(@template)).result((b||@block).binding)
216
318
  end
217
319
  alias_method 'to_s', 'expand'
218
320
  end
219
321
  def Template(*args, &block) Template.new(*args, &block) end
220
322
 
323
+ # colored console output support
324
+ #
325
+ This.ansi = {
326
+ :clear => "\e[0m",
327
+ :reset => "\e[0m",
328
+ :erase_line => "\e[K",
329
+ :erase_char => "\e[P",
330
+ :bold => "\e[1m",
331
+ :dark => "\e[2m",
332
+ :underline => "\e[4m",
333
+ :underscore => "\e[4m",
334
+ :blink => "\e[5m",
335
+ :reverse => "\e[7m",
336
+ :concealed => "\e[8m",
337
+ :black => "\e[30m",
338
+ :red => "\e[31m",
339
+ :green => "\e[32m",
340
+ :yellow => "\e[33m",
341
+ :blue => "\e[34m",
342
+ :magenta => "\e[35m",
343
+ :cyan => "\e[36m",
344
+ :white => "\e[37m",
345
+ :on_black => "\e[40m",
346
+ :on_red => "\e[41m",
347
+ :on_green => "\e[42m",
348
+ :on_yellow => "\e[43m",
349
+ :on_blue => "\e[44m",
350
+ :on_magenta => "\e[45m",
351
+ :on_cyan => "\e[46m",
352
+ :on_white => "\e[47m"
353
+ }
354
+ def say(phrase, *args)
355
+ options = args.last.is_a?(Hash) ? args.pop : {}
356
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
357
+ keys = options.keys
358
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
359
+
360
+ color = options[:color]
361
+ bold = options.has_key?(:bold)
362
+
363
+ parts = [phrase]
364
+ parts.unshift(This.ansi[color]) if color
365
+ parts.unshift(This.ansi[:bold]) if bold
366
+ parts.push(This.ansi[:clear]) if parts.size > 1
367
+
368
+ method = options[:method] || :puts
369
+
370
+ Kernel.send(method, parts.join)
371
+ end
372
+
373
+ # always run out of the project dir
374
+ #
221
375
  Dir.chdir(This.dir)
222
376
  }
@@ -32,6 +32,6 @@ BEGIN {
32
32
  yield
33
33
  ensure
34
34
  b = Time.now.to_f
35
- y label => (b - a)
35
+ puts({label => (b - a)}.to_yaml)
36
36
  end
37
37
  }
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  raise if a != b
30
30
 
31
- y :a => a, :b => b, :needle => needle
31
+ y({:a => a, :b => b, :needle => needle}.to_yaml)
32
32
 
33
33
  BEGIN {
34
34
  def time label
@@ -36,6 +36,6 @@ BEGIN {
36
36
  yield
37
37
  ensure
38
38
  b = Time.now.to_f
39
- y label => (b - a)
39
+ y({label => (b - a)})
40
40
  end
41
41
  }
@@ -3,24 +3,36 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "threadify"
6
- spec.version = "1.3.0"
6
+ spec.version = "1.4.3"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "threadify"
9
+ spec.description = "https://github.com/ahoward/threadify.git"
10
+ spec.license = "same as ruby's"
11
+
12
+ spec.files =
13
+ ["README",
14
+ "README.erb",
15
+ "lib",
16
+ "lib/threadify.rb",
17
+ "rakefile",
18
+ "sample",
19
+ "sample/a.rb",
20
+ "sample/b.rb",
21
+ "threadify.gemspec"]
9
22
 
10
- spec.files = ["lib", "lib/threadify.rb", "rakefile", "README", "README.erb", "sample", "sample/a.rb", "sample/b.rb", "threadify.gemspec"]
11
23
  spec.executables = []
12
24
 
13
25
  spec.require_path = "lib"
14
26
 
15
- spec.has_rdoc = true
16
27
  spec.test_files = nil
17
- #spec.add_dependency 'lib', '>= version'
18
- #spec.add_dependency 'fattr'
28
+
29
+ ### spec.add_dependency 'lib', '>= version'
30
+ #### spec.add_dependency 'map'
19
31
 
20
32
  spec.extensions.push(*[])
21
33
 
22
34
  spec.rubyforge_project = "codeforpeople"
23
35
  spec.author = "Ara T. Howard"
24
36
  spec.email = "ara.t.howard@gmail.com"
25
- spec.homepage = "http://github.com/ahoward/threadify/tree/master"
37
+ spec.homepage = "https://github.com/ahoward/threadify"
26
38
  end
metadata CHANGED
@@ -1,61 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: threadify
3
- version: !ruby/object:Gem::Version
4
- version: 1.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.3
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Ara T. Howard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-09-10 00:00:00 -06:00
13
- default_executable:
11
+ date: 2014-02-15 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
- description:
13
+ description: https://github.com/ahoward/threadify.git
17
14
  email: ara.t.howard@gmail.com
18
15
  executables: []
19
-
20
16
  extensions: []
21
-
22
17
  extra_rdoc_files: []
23
-
24
- files:
25
- - lib
26
- - lib/threadify.rb
27
- - rakefile
18
+ files:
28
19
  - README
29
20
  - README.erb
30
- - sample
21
+ - lib/threadify.rb
22
+ - rakefile
31
23
  - sample/a.rb
32
24
  - sample/b.rb
33
25
  - threadify.gemspec
34
- has_rdoc: true
35
- homepage: http://github.com/ahoward/threadify/tree/master
26
+ homepage: https://github.com/ahoward/threadify
27
+ licenses:
28
+ - same as ruby's
29
+ metadata: {}
36
30
  post_install_message:
37
31
  rdoc_options: []
38
-
39
- require_paths:
32
+ require_paths:
40
33
  - lib
41
- required_ruby_version: !ruby/object:Gem::Requirement
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
46
- version:
47
- required_rubygems_version: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: "0"
52
- version:
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
53
44
  requirements: []
54
-
55
45
  rubyforge_project: codeforpeople
56
- rubygems_version: 1.3.1
46
+ rubygems_version: 2.0.3
57
47
  signing_key:
58
- specification_version: 2
48
+ specification_version: 4
59
49
  summary: threadify
60
50
  test_files: []
61
-