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
-
close
can be called on the input stream to indicate that any remaining input is not needed.
-
-
#each(*args) ⇒ Object
-
each
must be called without arguments and only yield Strings.
-
-
#gets(*args) ⇒ Object
-
gets
must be called without arguments and return a string, ornil
on EOF.
-
-
#initialize(input) ⇒ InputWrapper
constructor
A new instance of InputWrapper.
-
#read(*args) ⇒ Object
-
read
behaves likeIO#read
.
-
Constructor Details
#initialize(input) ⇒ InputWrapper
Returns a new instance of InputWrapper.
452 453 454 |
# File 'lib/rack/lint.rb', line 452 def initialize(input) @input = input end |
Instance Method Details
#close(*args) ⇒ Object
-
close
can be called on the input stream to indicate that any remaining input is not needed.
529 530 531 |
# File 'lib/rack/lint.rb', line 529 def close(*args) @input.close(*args) end |
#each(*args) ⇒ Object
-
each
must be called without arguments and only yield Strings.
517 518 519 520 521 522 523 524 525 |
# File 'lib/rack/lint.rb', line 517 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, ornil
on EOF.
458 459 460 461 462 463 464 465 |
# File 'lib/rack/lint.rb', line 458 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 likeIO#read
. Its signature isread([length, [buffer]])
.If given,
length
must be a non-negative Integer (>= 0) ornil
, andbuffer
must be a String and may not be nil.If
length
is given and not nil, then this method reads at mostlength
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 “” iflength
is not given or is nil.If
buffer
is given, then the read data will be placed intobuffer
instead of a newly created String object.
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/rack/lint.rb', line 484 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 |