epitools 0.5.130 → 0.5.131
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/numbers.rb +8 -0
- data/lib/epitools/core_ext/uri.rb +8 -0
- data/lib/epitools/job_runner.rb +22 -4
- data/lib/epitools/path.rb +19 -10
- data/spec/core_ext_spec.rb +9 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 467e7148825ac612d6b8acc25da6c09e89521d734c38f64568b189f4c7df8b6e
|
|
4
|
+
data.tar.gz: 3319cb92d01f19e597cc00c4b30eb0b847e652e2fa53f8e63a96fff2dc6f2bc5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 518b4e0a4014fa2a0dbdeed3d2a3656887035526398062c29acfaf62b3acaf8a3fba81b55a15dc33efdc77818d359bf63c2dcb1cc1ecec0f14772052fadb25a2
|
|
7
|
+
data.tar.gz: f888b96dd3f917eb45977567bcd66b1a9972bae7ccaf3a8d82902964b7af569e1474dccbaade2379fa2ebb6e4073b74114e1c6b548a826481e6462de6979607a
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.131
|
data/lib/epitools/job_runner.rb
CHANGED
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
# end
|
|
27
27
|
#
|
|
28
28
|
class JobRunner
|
|
29
|
-
def initialize(*blocks)
|
|
29
|
+
def initialize(*blocks, debug: false)
|
|
30
30
|
@threads = []
|
|
31
31
|
@results = Thread::Queue.new
|
|
32
32
|
@jobs = []
|
|
33
33
|
@started = false
|
|
34
|
+
@debug = debug
|
|
34
35
|
|
|
35
36
|
if blocks.any?
|
|
36
37
|
blocks.each { |block| add &block }
|
|
@@ -39,20 +40,37 @@ class JobRunner
|
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
|
43
|
+
def dmsg(msg)
|
|
44
|
+
puts "[#{Time.now}] #{msg}" if @debug
|
|
45
|
+
end
|
|
46
|
+
|
|
42
47
|
def add(&block)
|
|
48
|
+
dmsg("added job #{block}")
|
|
43
49
|
@jobs << block
|
|
44
50
|
end
|
|
45
51
|
|
|
46
52
|
def reap!
|
|
47
|
-
|
|
53
|
+
if @threads.any?
|
|
54
|
+
dmsg("reaping #{@threads.size} threads")
|
|
55
|
+
@threads.delete_if { |t| not t.alive? }
|
|
56
|
+
else
|
|
57
|
+
dmsg("reap failed: no threads")
|
|
58
|
+
end
|
|
48
59
|
end
|
|
49
60
|
|
|
50
61
|
def go!
|
|
51
|
-
|
|
62
|
+
if @started
|
|
63
|
+
raise "Error: already started"
|
|
64
|
+
else
|
|
65
|
+
dmsg("starting #{@threads.size} jobs")
|
|
66
|
+
end
|
|
67
|
+
|
|
52
68
|
@started = true
|
|
53
69
|
@jobs.each do |job|
|
|
70
|
+
dmsg("adding #{job}")
|
|
54
71
|
@threads << Thread.new do
|
|
55
72
|
@results << job.call
|
|
73
|
+
dmsg("job #{job} complete")
|
|
56
74
|
end
|
|
57
75
|
end
|
|
58
76
|
end
|
|
@@ -72,7 +90,7 @@ end
|
|
|
72
90
|
|
|
73
91
|
|
|
74
92
|
if __FILE__ == $0
|
|
75
|
-
JobRunner.new do |jr|
|
|
93
|
+
JobRunner.new(debug: true) do |jr|
|
|
76
94
|
jr.add { 3 }
|
|
77
95
|
jr.add { sleep 0.1; 2 }
|
|
78
96
|
jr.add { sleep 0.2; 1 }
|
data/lib/epitools/path.rb
CHANGED
|
@@ -119,11 +119,20 @@ class Path
|
|
|
119
119
|
# The file extension, including the . (eg: ".mp3")
|
|
120
120
|
attr_reader :ext
|
|
121
121
|
|
|
122
|
+
URI_RE = %r{^[a-z\-]+://}i
|
|
122
123
|
|
|
123
124
|
###############################################################################
|
|
124
125
|
# Initializers
|
|
125
126
|
###############################################################################
|
|
126
127
|
|
|
128
|
+
def self.new(*args)
|
|
129
|
+
if args.first =~ URI_RE and self != Path::URI
|
|
130
|
+
Path::URI.new(args.first)
|
|
131
|
+
else
|
|
132
|
+
super(*args)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
127
136
|
def initialize(newpath, hints={})
|
|
128
137
|
send("path=", newpath, hints)
|
|
129
138
|
|
|
@@ -156,8 +165,8 @@ class Path
|
|
|
156
165
|
path
|
|
157
166
|
when String
|
|
158
167
|
|
|
159
|
-
if path =~
|
|
160
|
-
Path
|
|
168
|
+
if path =~ URI_RE
|
|
169
|
+
Path.new(path)
|
|
161
170
|
|
|
162
171
|
else
|
|
163
172
|
# TODO: highlight backgrounds of codeblocks to show indent level & put boxes (or rules?) around (between?) double-spaced regions
|
|
@@ -186,7 +195,7 @@ class Path
|
|
|
186
195
|
# Note: The `hints` parameter contains options so `path=` doesn't have to touch the filesytem as much.
|
|
187
196
|
#
|
|
188
197
|
def path=(newpath, hints={})
|
|
189
|
-
if hints[:type] or File.
|
|
198
|
+
if hints[:type] or File.exist? newpath
|
|
190
199
|
if hints[:type] == :dir or File.directory? newpath
|
|
191
200
|
self.dir = newpath
|
|
192
201
|
else
|
|
@@ -357,7 +366,7 @@ class Path
|
|
|
357
366
|
###############################################################################
|
|
358
367
|
|
|
359
368
|
def exists?
|
|
360
|
-
File.
|
|
369
|
+
File.exist? path
|
|
361
370
|
end
|
|
362
371
|
|
|
363
372
|
def size
|
|
@@ -430,7 +439,7 @@ class Path
|
|
|
430
439
|
end
|
|
431
440
|
|
|
432
441
|
def broken_symlink?
|
|
433
|
-
File.symlink?(path) and not File.
|
|
442
|
+
File.symlink?(path) and not File.exist?(path)
|
|
434
443
|
end
|
|
435
444
|
|
|
436
445
|
def symlink_target
|
|
@@ -1638,9 +1647,9 @@ class Path::URI < Path
|
|
|
1638
1647
|
#
|
|
1639
1648
|
# When this is: http://host.com:port/path/filename.ext?param1=value1¶m2=value2&...
|
|
1640
1649
|
#
|
|
1641
|
-
def to_s
|
|
1642
|
-
|
|
1643
|
-
end
|
|
1650
|
+
def to_s; uri.to_s; end
|
|
1651
|
+
def to_path; to_s; end
|
|
1652
|
+
def to_str; to_s; end
|
|
1644
1653
|
|
|
1645
1654
|
def inspect
|
|
1646
1655
|
"#<Path::URI:#{to_s}>"
|
|
@@ -1693,9 +1702,9 @@ class Path::URI < Path
|
|
|
1693
1702
|
def open(mode="r", &block)
|
|
1694
1703
|
require 'open-uri'
|
|
1695
1704
|
if block_given?
|
|
1696
|
-
|
|
1705
|
+
::URI.open(to_s, mode, &block)
|
|
1697
1706
|
else
|
|
1698
|
-
|
|
1707
|
+
::URI.open(to_s, mode)
|
|
1699
1708
|
end
|
|
1700
1709
|
end
|
|
1701
1710
|
|
data/spec/core_ext_spec.rb
CHANGED
|
@@ -1296,11 +1296,11 @@ describe URI do
|
|
|
1296
1296
|
uri.params.should == opts
|
|
1297
1297
|
end
|
|
1298
1298
|
|
|
1299
|
-
it "gets" do
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
end
|
|
1299
|
+
# it "gets" do
|
|
1300
|
+
# response = URI("http://google.com/").get
|
|
1301
|
+
# response.body.size
|
|
1302
|
+
# (response.size > 0).should == true
|
|
1303
|
+
# end
|
|
1304
1304
|
|
|
1305
1305
|
it "params=" do
|
|
1306
1306
|
u = "http://butt.cx/?q=1".to_uri
|
|
@@ -1310,6 +1310,10 @@ describe URI do
|
|
|
1310
1310
|
u.params["q"].should == 2
|
|
1311
1311
|
u.params.should == {"q" => 2}
|
|
1312
1312
|
u.query.should == "q=2"
|
|
1313
|
+
|
|
1314
|
+
subbed = u.with(query: u.params.reject{|k,v| u.params.keys.include? 'q' }.to_query)
|
|
1315
|
+
subbed.params.should == {}
|
|
1316
|
+
subbed.query.should == ""
|
|
1313
1317
|
end
|
|
1314
1318
|
|
|
1315
1319
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: epitools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.131
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- epitron
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|