Class: Rack::Lint::Wrapper::InputWrapper
- Inherits:
- Object
- Object
- Rack::Lint::Wrapper::InputWrapper
- Defined in:
- lib/rack/lint.rb
Instance Method Summary collapse
- #close(*args) ⇒ Object
-
closecan be called on the input stream to indicate that any remaining input is not needed.
-
- #each(*args) ⇒ Object
-
eachmust be called without arguments and only yieldStringvalues.
-
- #gets(*args) ⇒ Object
-
getsmust be called without arguments and return aString, ornilon EOF (end-of-file).
-
- #initialize(input) ⇒ InputWrapper constructor
A new instance of InputWrapper.
- #read(*args) ⇒ Object
-
readbehaves likeIO#read.
-
Constructor Details
#initialize(input) ⇒ InputWrapper
Returns a new instance of InputWrapper.
496 497 498 | # File 'lib/rack/lint.rb', line 496 def initialize(input) @input = input end |
Instance Method Details
#close(*args) ⇒ Object
-
closecan be called on the input stream to indicate that any remaining input is not needed.
563 564 565 | # File 'lib/rack/lint.rb', line 563 def close(*args) @input.close(*args) end |
#each(*args) ⇒ Object
-
eachmust be called without arguments and only yieldStringvalues.
552 553 554 555 556 557 558 559 560 | # File 'lib/rack/lint.rb', line 552 def each(*args) raise LintError, "rack.input#each called with arguments" unless args.size == 0 @input.each do |line| unless line.kind_of? String raise LintError, "rack.input#each didn't yield a String" end yield line end end |
#gets(*args) ⇒ Object
-
getsmust be called without arguments and return aString, ornilon EOF (end-of-file).
501 502 503 504 505 506 507 508 509 510 511 | # File 'lib/rack/lint.rb', line 501 def gets(*args) raise LintError, "rack.input#gets called with arguments" unless args.size == 0 chunk = @input.gets unless chunk.nil? or chunk.kind_of? String raise LintError, "rack.input#gets didn't return a String" end chunk end |
#read(*args) ⇒ Object
-
readbehaves likeIO#read. Its signature isread([length, [buffer]]).-
If given,
lengthmust be a non-negative Integer (>= 0) ornil, andbuffermust be aStringand may not benil. -
If
lengthis given and notnil, then this method reads at mostlengthbytes from the input stream. -
If
lengthis not given ornil, then this method reads all data until EOF. -
When EOF is reached, this method returns
niliflengthis given and notnil, or “” iflengthis not given or isnil. -
If
bufferis given, then the read data will be placed intobufferinstead of a newly createdString.
-
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | # File 'lib/rack/lint.rb', line 519 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 |