unix_utils 0.0.10 → 0.0.11
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/CHANGELOG +7 -1
- data/README.markdown +3 -3
- data/lib/unix_utils.rb +15 -4
- data/lib/unix_utils/version.rb +1 -1
- data/test/test_unix_utils.rb +6 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -21,11 +21,11 @@ Use a subprocess to perform a big task and then get out of memory.
|
|
21
21
|
|
22
22
|
<table>
|
23
23
|
<tr>
|
24
|
-
<td rowspan="2"><img src="https://
|
25
|
-
<td><img src="https://
|
24
|
+
<td rowspan="2"><img src="https://github.com/seamusabshere/unix_utils/raw/master/unix-philosophy-cover.png" alt="cover of the Unix Philosophy book" /></td>
|
25
|
+
<td><img src="https://github.com/seamusabshere/unix_utils/raw/master/unix-philosophy-quote-pg1.png" alt="Tenet 2: Make Each Program Do One Thing Well. The best programs, like Cousteau's lake fly, does but one task in its life and does it well. The program is loaded into memory, accomplishes its function, and then gets out ot the way to allow" /></td>
|
26
26
|
</tr>
|
27
27
|
<tr>
|
28
|
-
<td><img src="https://
|
28
|
+
<td><img src="https://github.com/seamusabshere/unix_utils/raw/master/unix-philosophy-quote-pg2.png" alt="the next single-minded program to begin. This sounds simple, yet it may surprise you how many software developers have difficulty sticking to this singular goal." /></td>
|
29
29
|
</tr>
|
30
30
|
</table>
|
31
31
|
|
data/lib/unix_utils.rb
CHANGED
@@ -12,9 +12,10 @@ module UnixUtils
|
|
12
12
|
|
13
13
|
def self.curl(url, form_data = nil)
|
14
14
|
outfile = tmp_path url
|
15
|
-
if url.start_with?('
|
15
|
+
if url.start_with?('file://') or url.start_with?('/') or url.count('/') == 0
|
16
16
|
# deal with local files
|
17
|
-
::
|
17
|
+
infile = ::File.expand_path url.sub('file://', '')
|
18
|
+
::FileUtils.cp infile, outfile
|
18
19
|
return outfile
|
19
20
|
end
|
20
21
|
uri = ::URI.parse url
|
@@ -176,7 +177,12 @@ module UnixUtils
|
|
176
177
|
|
177
178
|
def self.unix2dos(infile)
|
178
179
|
infile = ::File.expand_path infile
|
179
|
-
if available?('
|
180
|
+
if available?('unix2dos')
|
181
|
+
outfile = tmp_path infile
|
182
|
+
argv = ['unix2dos', '--force', '--newfile', infile, outfile ]
|
183
|
+
spawn argv
|
184
|
+
outfile
|
185
|
+
elsif available?('gawk') or available?('awk')
|
180
186
|
awk infile, '{ sub(/\r/, ""); printf("%s\r\n", $0) }'
|
181
187
|
else
|
182
188
|
perl infile, 's/\r\n|\n|\r/\r\n/g'
|
@@ -185,7 +191,12 @@ module UnixUtils
|
|
185
191
|
|
186
192
|
def self.dos2unix(infile)
|
187
193
|
infile = ::File.expand_path infile
|
188
|
-
if available?('
|
194
|
+
if available?('dos2unix')
|
195
|
+
outfile = tmp_path infile
|
196
|
+
argv = ['dos2unix', '--force', '--newfile', infile, outfile ]
|
197
|
+
spawn argv
|
198
|
+
outfile
|
199
|
+
elsif available?('gawk') or available?('awk')
|
189
200
|
awk infile, '{ sub(/\r/, ""); printf("%s\n", $0) }'
|
190
201
|
else
|
191
202
|
perl infile, 's/\r\n|\n|\r/\n/g'
|
data/lib/unix_utils/version.rb
CHANGED
data/test/test_unix_utils.rb
CHANGED
@@ -32,6 +32,12 @@ describe UnixUtils do
|
|
32
32
|
File.read(outfile).must_match %r{sustain}i
|
33
33
|
safe_delete outfile
|
34
34
|
end
|
35
|
+
|
36
|
+
it "deals safely with local files" do
|
37
|
+
UnixUtils.curl_s('utf8.txt').must_include 'Hola, ¿cómo estás?'
|
38
|
+
UnixUtils.curl_s(File.expand_path('utf8.txt')).must_include 'Hola, ¿cómo estás?'
|
39
|
+
UnixUtils.curl_s("file://#{File.expand_path('utf8.txt')}").must_include 'Hola, ¿cómo estás?'
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
describe :shasum do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unix_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: posix-spawn
|