unix_utils 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,10 @@
1
- 0.0.10 / 2012-14-23
1
+ 0.0.11 / 2012-05-07
2
+
3
+ * Bug fixes
4
+
5
+ * Fix handling of local files by UnixUtils.curl
6
+
7
+ 0.0.10 / 2012-04-23
2
8
 
3
9
  * Breaking changes
4
10
 
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://raw.github.com/seamusabshere/unix_utils/master/unix-philosophy-cover.png" alt="cover of the Unix Philosophy book" /></td>
25
- <td><img src="https://raw.github.com/seamusabshere/unix_utils/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>
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://raw.github.com/seamusabshere/unix_utils/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>
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?('/') or url.start_with?('file://')
15
+ if url.start_with?('file://') or url.start_with?('/') or url.count('/') == 0
16
16
  # deal with local files
17
- ::FileUtils.cp url.delete('file://'), path
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?('gawk') or available?('awk')
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?('gawk') or available?('awk')
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'
@@ -1,3 +1,3 @@
1
1
  module UnixUtils
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -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.10
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-04-23 00:00:00.000000000 Z
12
+ date: 2012-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: posix-spawn