Class: Puma::NullIO

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/null_io.rb

Overview

Provides an IO-like object that always appears to contain no data. Used as the value for rack.input when the request has no body.

Instance Method Summary collapse

Instance Method Details

#binmodeObject



93
94
95
# File 'lib/puma/null_io.rb', line 93

def binmode
  self
end

#binmode?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/puma/null_io.rb', line 97

def binmode?
  true
end

#closeObject



51
52
# File 'lib/puma/null_io.rb', line 51

def close
end

#closed?Boolean

This is used as singleton class, so can’t have state.

Returns:

  • (Boolean)


80
81
82
# File 'lib/puma/null_io.rb', line 80

def closed?
  false
end

#eachObject



16
17
# File 'lib/puma/null_io.rb', line 16

def each
end

#eof?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/puma/null_io.rb', line 58

def eof?
  true
end

#external_encodingObject

per rack spec



89
90
91
# File 'lib/puma/null_io.rb', line 89

def external_encoding
  Encoding::ASCII_8BIT
end

#flushObject



75
76
77
# File 'lib/puma/null_io.rb', line 75

def flush
  self
end

#getsObject



8
9
10
# File 'lib/puma/null_io.rb', line 8

def gets
  nil
end

#posObject



19
20
21
# File 'lib/puma/null_io.rb', line 19

def pos
  0
end

#puts(*ary) ⇒ Object



69
70
# File 'lib/puma/null_io.rb', line 69

def puts(*ary)
end

#read(length = nil, buffer = nil) ⇒ Object

Mimics IO#read with no data.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puma/null_io.rb', line 25

def read(length = nil, buffer = nil)
  if length.to_i < 0
    raise ArgumentError, "(negative length #{length} given)"
  end

  buffer = if buffer.nil?
    "".b
  else
    String.try_convert(buffer) or raise TypeError, "no implicit conversion of #{buffer.class} into String"
  end
  buffer.clear
  if length.to_i > 0
    nil
  else
    buffer
  end
end

#rewindObject



43
44
# File 'lib/puma/null_io.rb', line 43

def rewind
end

#seek(pos, whence = 0) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
# File 'lib/puma/null_io.rb', line 46

def seek(pos, whence = 0)
  raise ArgumentError, "negative length #{pos} given" if pos.negative?
  0
end

#set_encoding(enc) ⇒ Object



84
85
86
# File 'lib/puma/null_io.rb', line 84

def set_encoding(enc)
  self
end

#sizeObject



54
55
56
# File 'lib/puma/null_io.rb', line 54

def size
  0
end

#stringObject



12
13
14
# File 'lib/puma/null_io.rb', line 12

def string
  ""
end

#syncObject



62
63
64
# File 'lib/puma/null_io.rb', line 62

def sync
  true
end

#sync=(v) ⇒ Object



66
67
# File 'lib/puma/null_io.rb', line 66

def sync=(v)
end

#write(*ary) ⇒ Object



72
73
# File 'lib/puma/null_io.rb', line 72

def write(*ary)
end