Class: Rack::Lint::Wrapper::InputWrapper
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rack/lint.rb |
Class Method Summary
- .new(input) ⇒ InputWrapper constructor
Instance Method Summary
-
#close(*args)
#close can be called on the input stream to indicate that any remaining input is not needed.
-
#each(*args)
#each must be called without arguments and only yield
String
values.
-
#gets(*args)
#gets must be called without arguments and return a string, or
nil
on EOF.
-
#read(*args)
#read behaves like
IO#read
.
Constructor Details
.new(input) ⇒ InputWrapper
# File 'lib/rack/lint.rb', line 497
def initialize(input) @input = input end
Instance Method Details
#close(*args)
-
close
can be called on the input stream to indicate that any remaining input is not needed.
# File 'lib/rack/lint.rb', line 564
def close(*args) @input.close(*args) end
#each(*args)
-
each
must be called without arguments and only yieldString
values.
#gets(*args)
-
gets
must be called without arguments and return a string, ornil
on EOF.
#read(*args)
-
read
behaves likeIO#read
. Its signature isread([length, [buffer]])
.-
If given,
length
must be a non-negative Integer (>= 0) ornil
, andbuffer
must be aString
and may not benil
. -
If
length
is given and notnil
, then this method reads at mostlength
bytes from the input stream. -
If
length
is not given ornil
, then this method reads all data until EOF. -
When EOF is reached, this method returns
nil
iflength
is given and notnil
, or“”
iflength
is not given or isnil
. -
If
buffer
is given, then the read data will be placed intobuffer
instead of a newly createdString
object.
-
# File 'lib/rack/lint.rb', line 520
def read(*args) unless args.size <= 2 raise LintError, "rack.input#read called with too many arguments" end if args.size >= 1 unless args.first.kind_of?(Integer) || args.first.nil? raise LintError, "rack.input#read called with non-integer and non-nil length" end unless args.first.nil? || args.first >= 0 raise LintError, "rack.input#read called with a negative length" end end if args.size >= 2 unless args[1].kind_of?(String) raise LintError, "rack.input#read called with non-String buffer" end end chunk = @input.read(*args) unless chunk.nil? or chunk.kind_of? String raise LintError, "rack.input#read didn't return nil or a String" end if args[0].nil? unless !chunk.nil? raise LintError, "rack.input#read(nil) returned nil on EOF" end end chunk end