Module: Sinatra::Streaming::Stream
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/sinatra/streaming.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#closed ⇒ Object
(also: #closed?)
Returns the value of attribute closed.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
-
#pos ⇒ Object
(also: #tell)
Returns the value of attribute pos.
-
#transformer ⇒ Object
Returns the value of attribute transformer.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #close ⇒ Object
- #close_read ⇒ Object
- #closed_read? ⇒ Boolean
- #closed_write? ⇒ Boolean
- #dummy ⇒ Object (also: #flush, #fsync, #internal_encoding, #pid)
- #each ⇒ Object
- #enum_not_open_for_reading ⇒ Object (also: #chars, #each_line, #each_byte, #each_char, #lines)
- #external_encoding ⇒ Object
- #map(&block) ⇒ Object
- #map!(&block) ⇒ Object
- #print(*args) ⇒ Object
- #printf(format, *args) ⇒ Object
- #putc(c) ⇒ Object
- #puts(*args) ⇒ Object
- #rewind ⇒ Object
- #seek ⇒ Object (also: #sysseek)
- #settings ⇒ Object
- #sync ⇒ Object
- #tty? ⇒ Boolean (also: #isatty)
- #write(data) ⇒ Object (also: #syswrite, #write_nonblock)
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
108 109 110 |
# File 'lib/sinatra/streaming.rb', line 108 def app @app end |
#closed ⇒ Object Also known as: closed?
Returns the value of attribute closed.
108 109 110 |
# File 'lib/sinatra/streaming.rb', line 108 def closed @closed end |
#lineno ⇒ Object
Returns the value of attribute lineno.
108 109 110 |
# File 'lib/sinatra/streaming.rb', line 108 def lineno @lineno end |
#pos ⇒ Object Also known as: tell
Returns the value of attribute pos.
108 109 110 |
# File 'lib/sinatra/streaming.rb', line 108 def pos @pos end |
#transformer ⇒ Object
Returns the value of attribute transformer.
108 109 110 |
# File 'lib/sinatra/streaming.rb', line 108 def transformer @transformer end |
Class Method Details
.extended(obj) ⇒ Object
112 113 114 115 116 |
# File 'lib/sinatra/streaming.rb', line 112 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
118 119 120 121 122 123 124 |
# File 'lib/sinatra/streaming.rb', line 118 def <<(data) raise IOError, 'not opened for writing' if closed? data = data.to_s data = @transformer[data] if @transformer @pos += data.bytesize super(data) end |
#close ⇒ Object
172 173 174 175 |
# File 'lib/sinatra/streaming.rb', line 172 def close @scheduler.schedule { succeed } nil end |
#close_read ⇒ Object
177 178 179 |
# File 'lib/sinatra/streaming.rb', line 177 def close_read raise IOError, "closing non-duplex IO for reading" end |
#closed_read? ⇒ Boolean
181 182 183 |
# File 'lib/sinatra/streaming.rb', line 181 def closed_read? true end |
#closed_write? ⇒ Boolean
185 186 187 |
# File 'lib/sinatra/streaming.rb', line 185 def closed_write? closed? end |
#dummy ⇒ Object Also known as: flush, fsync, internal_encoding, pid
241 |
# File 'lib/sinatra/streaming.rb', line 241 def dummy(*) end |
#each ⇒ Object
126 127 128 129 130 |
# File 'lib/sinatra/streaming.rb', line 126 def each # that way body.each.map { ... } works return self unless block_given? super end |
#enum_not_open_for_reading ⇒ Object Also known as: chars, each_line, each_byte, each_char, lines
229 230 231 232 |
# File 'lib/sinatra/streaming.rb', line 229 def enum_not_open_for_reading(*) not_open_for_reading if block_given? enum_for(:not_open_for_reading) end |
#external_encoding ⇒ Object
189 190 191 192 193 |
# File 'lib/sinatra/streaming.rb', line 189 def external_encoding Encoding.find settings.default_encoding rescue NameError settings.default_encoding end |
#map(&block) ⇒ Object
132 133 134 135 |
# File 'lib/sinatra/streaming.rb', line 132 def map(&block) # dup would not copy the mixin clone.map!(&block) end |
#map!(&block) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/sinatra/streaming.rb', line 137 def map!(&block) if @transformer inner, outer = @transformer, block block = proc { |value| outer[inner[value]] } end @transformer = block self end |
#print(*args) ⇒ Object
154 155 156 157 |
# File 'lib/sinatra/streaming.rb', line 154 def print(*args) args.each { |arg| self << arg } nil end |
#printf(format, *args) ⇒ Object
159 160 161 |
# File 'lib/sinatra/streaming.rb', line 159 def printf(format, *args) print(format.to_s % args) end |
#putc(c) ⇒ Object
163 164 165 |
# File 'lib/sinatra/streaming.rb', line 163 def putc(c) print c.chr end |
#puts(*args) ⇒ Object
167 168 169 170 |
# File 'lib/sinatra/streaming.rb', line 167 def puts(*args) args.each { |arg| self << "#{arg}\n" } nil end |
#rewind ⇒ Object
203 204 205 |
# File 'lib/sinatra/streaming.rb', line 203 def rewind @pos = @lineno = 0 end |
#seek ⇒ Object Also known as: sysseek
248 249 250 |
# File 'lib/sinatra/streaming.rb', line 248 def seek(*) 0 end |
#settings ⇒ Object
199 200 201 |
# File 'lib/sinatra/streaming.rb', line 199 def settings app.settings end |
#sync ⇒ Object
254 255 256 |
# File 'lib/sinatra/streaming.rb', line 254 def sync true end |
#tty? ⇒ Boolean Also known as: isatty
258 259 260 |
# File 'lib/sinatra/streaming.rb', line 258 def tty? false end |
#write(data) ⇒ Object Also known as: syswrite, write_nonblock
146 147 148 149 |
# File 'lib/sinatra/streaming.rb', line 146 def write(data) self << data data.to_s.bytesize end |