Skip to content

Commit

Permalink
experimental feature: UnixUtils.head_s -> string
Browse files Browse the repository at this point in the history
  • Loading branch information
seamusabshere committed Apr 13, 2012
1 parent 206c13e commit bb388e7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
24 changes: 15 additions & 9 deletions History.txt → CHANGELOG
@@ -1,28 +1,34 @@
== 0.0.9 / 2012-04-12
unreleased

* Enhancements

* If you call a method with _s at the end, you get a string back. For example: UnixUtils.head_s

0.0.9 / 2012-04-12

* Bug fixes

* Correct implementation of :read_from

== 0.0.8 / 2012-04-12
0.0.8 / 2012-04-12

* Bug fixes

* Let perl handle its own input files (ARGF)... my implementation using IO.select was not working.

== 0.0.7 / 2012-04-11
0.0.7 / 2012-04-11

* Bug fixes

* Make sure UnixUtils.tmp_path doesn't create too-long filenames

== 0.0.6 / 2012-04-11
0.0.6 / 2012-04-11

* Enhancements

* iconv command silently discards invalid characters

== 0.0.5 / 2012-03-21
0.0.5 / 2012-03-21

* Enhancements

Expand All @@ -32,13 +38,13 @@

* Thanks to @leomao10, make sed work more reliably on large files by using its input-file argument rather than piping in data

== 0.0.4 / 2012-03-19
0.0.4 / 2012-03-19

* Bug fixes

* NoMethodError when trying to print $stderr - thanks @leomao10 !

== 0.0.3 / 2012-03-19
0.0.3 / 2012-03-19

* Enhancements

Expand All @@ -49,12 +55,12 @@

* Correctly use pipes (I hope) - imitate POSIX::Spawn::Child's use of IO.select

== 0.0.2 / 2012-02-16
0.0.2 / 2012-02-16

* Bug fixes

* Fix use of splat internally so that it actually runs in MRI 1.8.7 and JRuby

== 0.0.1 / 2012-02-16 (yanked!)
0.0.1 / 2012-02-16 (yanked!)

* Birthday!
14 changes: 14 additions & 0 deletions lib/unix_utils.rb
Expand Up @@ -324,4 +324,18 @@ def self.spawn(argv, options = {}) # :nodoc:
ensure
[stdin, stdout, stderr, input, output, error].each { |io| io.close if io and not io.closed? }
end

def self.method_missing(method_id, *args)
base_method_id = method_id.to_s.chomp('_s')
if respond_to?(base_method_id)
begin
outfile = send(*([base_method_id]+args))

This comment has been minimized.

Copy link
@rossmeissl

rossmeissl Apr 13, 2012

You might prefer

send *args.unshift(base_method_id)

This comment has been minimized.

Copy link
@seamusabshere

seamusabshere Apr 13, 2012

Author Owner

jruby doesn't like naked splats

::File.read outfile
ensure
::FileUtils.rm_f outfile
end
else
super
end
end
end
8 changes: 8 additions & 0 deletions test/test_unix_utils.rb
Expand Up @@ -342,6 +342,10 @@
File.read(outfile).must_equal @a2z[2..-1].join("\n")
safe_delete outfile
end
it 'has a related tail_s method' do
str = UnixUtils.tail_s(@infile, 3)
str.must_equal @a2z.last(3).join("\n")
end
end

describe :head do
Expand All @@ -360,6 +364,10 @@
File.read(outfile).must_equal(@a2z.first(3).join("\n") + "\n")
safe_delete outfile
end
it 'has a related head_s method' do
str = UnixUtils.head_s(@infile, 3)
str.must_equal(@a2z.first(3).join("\n") + "\n")
end
end

describe :cut do
Expand Down

0 comments on commit bb388e7

Please sign in to comment.