mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
This commit was manufactured by cvs2svn to create branch 'ruby_1_6'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4fc74dc0b2
commit
b119069bac
9 changed files with 2001 additions and 0 deletions
111
lib/shell/filter.rb
Normal file
111
lib/shell/filter.rb
Normal file
|
@ -0,0 +1,111 @@
|
|||
#
|
||||
# shell/filter.rb -
|
||||
# $Release Version: 0.6.0 $
|
||||
# $Revision$
|
||||
# $Date$
|
||||
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
|
||||
#
|
||||
# --
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
class Shell
|
||||
#
|
||||
# Filter
|
||||
# A method to require
|
||||
# each()
|
||||
#
|
||||
class Filter
|
||||
include Enumerable
|
||||
include Error
|
||||
|
||||
def initialize(sh)
|
||||
@shell = sh # parent shell
|
||||
@input = nil # input filter
|
||||
end
|
||||
|
||||
attr_reader :input
|
||||
|
||||
def input=(filter)
|
||||
@input = filter
|
||||
end
|
||||
|
||||
def each(rs = nil)
|
||||
rs = @shell.record_separator unless rs
|
||||
if @input
|
||||
@input.each(rs){|l| yield l}
|
||||
end
|
||||
end
|
||||
|
||||
def < (src)
|
||||
case src
|
||||
when String
|
||||
cat = Cat.new(@shell, src)
|
||||
cat | self
|
||||
when IO
|
||||
self.input = src
|
||||
self
|
||||
else
|
||||
Filter.Fail CanNotMethodApply, "<", to.type
|
||||
end
|
||||
end
|
||||
|
||||
def > (to)
|
||||
case to
|
||||
when String
|
||||
dst = @shell.open(to, "w")
|
||||
begin
|
||||
each(){|l| dst << l}
|
||||
ensure
|
||||
dst.close
|
||||
end
|
||||
when IO
|
||||
each(){|l| to << l}
|
||||
else
|
||||
Filter.Fail CanNotMethodApply, ">", to.type
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def >> (to)
|
||||
begin
|
||||
Shell.cd(@shell.pwd).append(to, self)
|
||||
rescue CanNotMethodApply
|
||||
Shell.Fail CanNotMethodApply, ">>", to.type
|
||||
end
|
||||
end
|
||||
|
||||
def | (filter)
|
||||
filter.input = self
|
||||
if active?
|
||||
@shell.process_controller.start_job filter
|
||||
end
|
||||
filter
|
||||
end
|
||||
|
||||
def + (filter)
|
||||
Join.new(@shell, self, filter)
|
||||
end
|
||||
|
||||
def to_a
|
||||
ary = []
|
||||
each(){|l| ary.push l}
|
||||
ary
|
||||
end
|
||||
|
||||
def to_s
|
||||
str = ""
|
||||
each(){|l| str.concat l}
|
||||
str
|
||||
end
|
||||
|
||||
def inspect
|
||||
if @shell.debug.kind_of?(Integer) && @shell.debug > 2
|
||||
super
|
||||
else
|
||||
to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue