Module: Sinatra::Streaming::Stream

Defined in:
lib/sinatra/streaming.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app.



89
90
91
# File 'lib/sinatra/streaming.rb', line 89

def app
  @app
end

#closedObject Also known as: closed?

Returns the value of attribute closed.



89
90
91
# File 'lib/sinatra/streaming.rb', line 89

def closed
  @closed
end

#linenoObject

Returns the value of attribute lineno.



89
90
91
# File 'lib/sinatra/streaming.rb', line 89

def lineno
  @lineno
end

#posObject Also known as: tell

Returns the value of attribute pos.



89
90
91
# File 'lib/sinatra/streaming.rb', line 89

def pos
  @pos
end

#transformerObject

Returns the value of attribute transformer.



89
90
91
# File 'lib/sinatra/streaming.rb', line 89

def transformer
  @transformer
end

Class Method Details

.extended(obj) ⇒ Object



93
94
95
96
97
# File 'lib/sinatra/streaming.rb', line 93

def self.extended(obj)
  obj.closed, obj.lineno, obj.pos = false, 0, 0
  obj.callback { obj.closed = true }
  obj.errback  { obj.closed = true }
end

Instance Method Details

#<<(data) ⇒ Object

Raises:

  • (IOError)


99
100
101
102
103
104
105
106
107
# File 'lib/sinatra/streaming.rb', line 99

def <<(data)
  raise IOError, 'not opened for writing' if closed?

  @transformer ||= nil
  data = data.to_s
  data = @transformer[data] if @transformer
  @pos += data.bytesize
  super(data)
end

#close_readObject

Raises:

  • (IOError)


157
158
159
# File 'lib/sinatra/streaming.rb', line 157

def close_read
  raise IOError, "closing non-duplex IO for reading"
end

#closed_read?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/sinatra/streaming.rb', line 161

def closed_read?
  true
end

#closed_write?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/sinatra/streaming.rb', line 165

def closed_write?
  closed?
end

#dummyObject Also known as: flush, fsync, internal_encoding, pid



221
# File 'lib/sinatra/streaming.rb', line 221

def dummy(*) end

#eachObject



109
110
111
112
113
# File 'lib/sinatra/streaming.rb', line 109

def each
  # that way body.each.map { ... } works
  return self unless block_given?
  super
end

#enum_not_open_for_readingObject Also known as: chars, each_line, each_byte, each_char, lines



209
210
211
212
# File 'lib/sinatra/streaming.rb', line 209

def enum_not_open_for_reading(*)
  not_open_for_reading if block_given?
  enum_for(:not_open_for_reading)
end

#external_encodingObject



169
170
171
172
173
# File 'lib/sinatra/streaming.rb', line 169

def external_encoding
  Encoding.find settings.default_encoding
rescue NameError
  settings.default_encoding
end

#map(&block) ⇒ Object



115
116
117
118
# File 'lib/sinatra/streaming.rb', line 115

def map(&block)
  # dup would not copy the mixin
  clone.map!(&block)
end

#map!(&block) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'lib/sinatra/streaming.rb', line 120

def map!(&block)
  @transformer ||= nil

  if @transformer
    inner, outer = @transformer, block
    block = proc { |value| outer[inner[value]] }
  end
  @transformer = block
  self
end


139
140
141
142
# File 'lib/sinatra/streaming.rb', line 139

def print(*args)
  args.each { |arg| self << arg }
  nil
end

#printf(format, *args) ⇒ Object



144
145
146
# File 'lib/sinatra/streaming.rb', line 144

def printf(format, *args)
  print(format.to_s % args)
end

#putc(c) ⇒ Object



148
149
150
# File 'lib/sinatra/streaming.rb', line 148

def putc(c)
  print c.chr
end

#puts(*args) ⇒ Object



152
153
154
155
# File 'lib/sinatra/streaming.rb', line 152

def puts(*args)
  args.each { |arg| self << "#{arg}\n" }
  nil
end

#rewindObject



183
184
185
# File 'lib/sinatra/streaming.rb', line 183

def rewind
  @pos = @lineno = 0
end

#seekObject Also known as: sysseek



228
229
230
# File 'lib/sinatra/streaming.rb', line 228

def seek(*)
  0
end

#settingsObject



179
180
181
# File 'lib/sinatra/streaming.rb', line 179

def settings
  app.settings
end

#syncObject



234
235
236
# File 'lib/sinatra/streaming.rb', line 234

def sync
  true
end

#tty?Boolean Also known as: isatty

Returns:

  • (Boolean)


238
239
240
# File 'lib/sinatra/streaming.rb', line 238

def tty?
  false
end

#write(data) ⇒ Object Also known as: syswrite, write_nonblock



131
132
133
134
# File 'lib/sinatra/streaming.rb', line 131

def write(data)
  self << data
  data.to_s.bytesize
end