Class: Rack::Lint::InputWrapper

Inherits:
Object
  • Object
show all
Includes:
Assertion
Defined in:
lib/gems/rack-0.9.1/lib/rack/lint.rb

Instance Method Summary collapse

Methods included from Assertion

#assert

Constructor Details

#initialize(input) ⇒ InputWrapper

Returns a new instance of InputWrapper.



213
214
215
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 213

def initialize(input)
  @input = input
end

Instance Method Details

#close(*args) ⇒ Object

  • close must never be called on the input stream.



266
267
268
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 266

def close(*args)
  assert("rack.input#close must not be called") { false }
end

#each(*args) ⇒ Object

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



255
256
257
258
259
260
261
262
263
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 255

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.instance_of? String
    }
    yield line
  }
end

#gets(*args) ⇒ Object

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



227
228
229
230
231
232
233
234
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 227

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.instance_of? String
  }
  v
end

#read(*args) ⇒ Object

  • read must be called without or with one integer argument and return a string, or nil on EOF.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 238

def read(*args)
  assert("rack.input#read called with too many arguments") {
    args.size <= 1
  }
  if args.size == 1
    assert("rack.input#read called with non-integer argument") {
      args.first.kind_of? Integer
    }
  end
  v = @input.read(*args)
  assert("rack.input#read didn't return a String") {
    v.nil? or v.instance_of? String
  }
  v
end

#rewindObject



221
222
223
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 221

def rewind
  @input.rewind
end

#sizeObject



217
218
219
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 217

def size
  @input.size
end