Class: Rack::Lint::InputWrapper
- Inherits:
 - 
      Object
      
        
- Object
 - Rack::Lint::InputWrapper
 
 
- Includes:
 - Assertion
 
- Defined in:
 - lib/rack/lint.rb
 
Instance Method Summary collapse
- 
  
    
      #close(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
closemust never be called on the input stream. 
 - 
 - 
  
    
      #each(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
eachmust be called without arguments and only yield Strings. 
 - 
 - 
  
    
      #gets(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
getsmust be called without arguments and return a string, ornilon EOF. 
 - 
 - 
  
    
      #initialize(input)  ⇒ InputWrapper 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of InputWrapper.
 - 
  
    
      #read(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
readbehaves like IO#read. 
 - 
 - 
  
    
      #rewind(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
rewindmust be called without arguments. 
 - 
 
Methods included from Assertion
Constructor Details
#initialize(input) ⇒ InputWrapper
Returns a new instance of InputWrapper.
      398 399 400  | 
    
      # File 'lib/rack/lint.rb', line 398 def initialize(input) @input = input end  | 
  
Instance Method Details
#close(*args) ⇒ Object
- 
closemust never be called on the input stream. 
      491 492 493  | 
    
      # File 'lib/rack/lint.rb', line 491 def close(*args) assert("rack.input#close must not be called") { false } end  | 
  
#each(*args) ⇒ Object
- 
eachmust be called without arguments and only yield Strings. 
      463 464 465 466 467 468 469 470 471  | 
    
      # File 'lib/rack/lint.rb', line 463 def each(*args) assert("rack.input#each called with arguments") { args.size == 0 } @input.each { |line| assert("rack.input#each didn't yield a String") { line.kind_of? String } yield line } end  | 
  
#gets(*args) ⇒ Object
- 
getsmust be called without arguments and return a string, ornilon EOF. 
      404 405 406 407 408 409 410 411  | 
    
      # File 'lib/rack/lint.rb', line 404 def gets(*args) assert("rack.input#gets called with arguments") { args.size == 0 } v = @input.gets assert("rack.input#gets didn't return a String") { v.nil? or v.kind_of? String } v end  | 
  
#read(*args) ⇒ Object
- 
readbehaves like IO#read. Its signature isread([length, [buffer]]).If given,
lengthmust be a non-negative Integer (>= 0) ornil, andbuffermust be a String and may not be nil.If
lengthis given and not nil, then this method reads at mostlengthbytes from the input stream.If
lengthis not given or nil, then this method reads all data until EOF.When EOF is reached, this method returns nil if
lengthis given and not nil, or “” iflengthis not given or is nil.If
bufferis given, then the read data will be placed intobufferinstead of a newly created String object. 
      430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460  | 
    
      # File 'lib/rack/lint.rb', line 430 def read(*args) assert("rack.input#read called with too many arguments") { args.size <= 2 } if args.size >= 1 assert("rack.input#read called with non-integer and non-nil length") { args.first.kind_of?(Integer) || args.first.nil? } assert("rack.input#read called with a negative length") { args.first.nil? || args.first >= 0 } end if args.size >= 2 assert("rack.input#read called with non-String buffer") { args[1].kind_of?(String) } end v = @input.read(*args) assert("rack.input#read didn't return nil or a String") { v.nil? or v.kind_of? String } if args[0].nil? assert("rack.input#read(nil) returned nil on EOF") { !v.nil? } end v end  | 
  
#rewind(*args) ⇒ Object
- 
rewindmust be called without arguments. It rewinds the input stream back to the beginning. It must not raise Errno::ESPIPE: that is, it may not be a pipe or a socket. Therefore, handler developers must buffer the input data into some rewindable object if the underlying input stream is not rewindable. 
      478 479 480 481 482 483 484 485 486 487 488  | 
    
      # File 'lib/rack/lint.rb', line 478 def rewind(*args) assert("rack.input#rewind called with arguments") { args.size == 0 } assert("rack.input#rewind raised Errno::ESPIPE") { begin @input.rewind true rescue Errno::ESPIPE false end } end  |