Class: Rack::Lint::InputWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/lint.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ InputWrapper

Returns a new instance of InputWrapper.


393
394
395
# File 'lib/rack/lint.rb', line 393

def initialize(input)
  @input = input
end

Instance Method Details

#close(*args) ⇒ Object

  • close must never be called on the input stream.

Raises:


484
485
486
# File 'lib/rack/lint.rb', line 484

def close(*args)
  raise LintError, "rack.input#close must not be called"
end

#each(*args) ⇒ Object

  • each must be called without arguments and only yield Strings.

Raises:


458
459
460
461
462
463
464
465
466
# File 'lib/rack/lint.rb', line 458

def each(*args)
  raise LintError, "rack.input#each called with arguments" unless args.size == 0
  @input.each { |line|
    unless line.kind_of? String
      raise LintError, "rack.input#each didn't yield a String"
    end
    yield line
  }
end

#gets(*args) ⇒ Object

  • gets must be called without arguments and return a string, or nil on EOF.

Raises:


399
400
401
402
403
404
405
406
# File 'lib/rack/lint.rb', line 399

def gets(*args)
  raise LintError, "rack.input#gets called with arguments" unless args.size == 0
  v = @input.gets
  unless v.nil? or v.kind_of? String
    raise LintError, "rack.input#gets didn't return a String"
  end
  v
end

#read(*args) ⇒ Object

  • read behaves like IO#read. Its signature is read([length, [buffer]]).

    If given, length must be a non-negative Integer (>= 0) or nil, and buffer must be a String and may not be nil.

    If length is given and not nil, then this method reads at most length bytes from the input stream.

    If length is not given or nil, then this method reads all data until EOF.

    When EOF is reached, this method returns nil if length is given and not nil, or “” if length is not given or is nil.

    If buffer is given, then the read data will be placed into buffer instead of a newly created String object.


425
426
427
428
429
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
# File 'lib/rack/lint.rb', line 425

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

  v = @input.read(*args)

  unless v.nil? or v.kind_of? String
    raise LintError, "rack.input#read didn't return nil or a String"
  end
  if args[0].nil?
    unless !v.nil?
      raise LintError, "rack.input#read(nil) returned nil on EOF"
    end
  end

  v
end

#rewind(*args) ⇒ Object

  • rewind must 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.

Raises:


473
474
475
476
477
478
479
480
481
# File 'lib/rack/lint.rb', line 473

def rewind(*args)
  raise LintError, "rack.input#rewind called with arguments" unless args.size == 0
  begin
    @input.rewind
    true
  rescue Errno::ESPIPE
    raise LintError, "rack.input#rewind raised Errno::ESPIPE"
  end
end