123456789_123456789_123456789_123456789_123456789_

Module: Sinatra::Streaming::Stream

Relationships & Source Files
Defined in: sinatra-contrib/lib/sinatra/streaming.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.extended(obj)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 92

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

Instance Attribute Details

#app (rw)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 88

attr_accessor :app, :lineno, :pos, :transformer, :closed

#closed? (rw)

Alias for #closed.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 90

alias closed? closed

#closed_read?Boolean (readonly)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 164

def closed_read?
  true
end

#closed_write?Boolean (readonly)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 168

def closed_write?
  closed?
end

#isatty (readonly)

Alias for #tty?.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 241

alias isatty tty?

#lineno (rw)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 88

attr_accessor :app, :lineno, :pos, :transformer, :closed

#pos (rw) Also known as: #tell

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 88

attr_accessor :app, :lineno, :pos, :transformer, :closed

#tell (readonly)

Alias for #pos.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 89

alias tell pos

#transformer (rw)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 88

attr_accessor :app, :lineno, :pos, :transformer, :closed

#tty?Boolean (readonly) Also known as: #isatty

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 237

def tty?
  false
end

Instance Method Details

#<<(data)

Raises:

  • (IOError)
[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 100

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

#bytes

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 190

alias bytes         not_open_for_reading

#chars

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 213

alias chars     enum_not_open_for_reading

#close_read

Raises:

  • (IOError)
[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 160

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

#closed (rw) Also known as: #closed?

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 88

attr_accessor :app, :lineno, :pos, :transformer, :closed

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 220

def dummy(*) end

#each

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 110

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

  super
end

#each_byte

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 215

alias each_byte enum_not_open_for_reading

#each_char

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 216

alias each_char enum_not_open_for_reading

#each_line

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 214

alias each_line enum_not_open_for_reading

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 208

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

#eof

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 192

alias eof           not_open_for_reading

#eof?

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 191

alias eof?          not_open_for_reading

#external_encoding

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 172

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

#flush

Alias for #dummy.

[ GitHub ]

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

alias flush             dummy

#fsync

Alias for #dummy.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 222

alias fsync             dummy

#getbyte

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 193

alias getbyte       not_open_for_reading

#getc

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 194

alias getc          not_open_for_reading

#gets

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 195

alias gets          not_open_for_reading

#internal_encoding

Alias for #dummy.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 223

alias internal_encoding dummy

#lines

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 217

alias lines     enum_not_open_for_reading

#map(&block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 117

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

#map!(&block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 122

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

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

#not_open_for_reading (private) Also known as: #bytes, #eof?, #eof, #getbyte, #getc, #gets, #read, #read_nonblock, #readbyte, #readchar, #readline, #readlines, #readpartial, #sysread, #ungetbyte, #ungetc

Raises:

  • (IOError)
[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 186

def not_open_for_reading(*)
  raise IOError, 'not opened for reading'
end

#pid

Alias for #dummy.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 224

alias pid               dummy

#printf(format, *args)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 147

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

#putc(c)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 151

def putc(c)
  print c.chr
end

#puts(*args)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 155

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

#read

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 196

alias read          not_open_for_reading

#read_nonblock

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 197

alias read_nonblock not_open_for_reading

#readbyte

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 198

alias readbyte      not_open_for_reading

#readchar

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 199

alias readchar      not_open_for_reading

#readline

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 200

alias readline      not_open_for_reading

#readlines

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 201

alias readlines     not_open_for_reading

#readpartial

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 202

alias readpartial   not_open_for_reading

#rewind

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 182

def rewind
  @pos = @lineno = 0
end

#seek Also known as: #sysseek

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 227

def seek(*)
  0
end

#settings

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 178

def settings
  app.settings
end

#sync

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 233

def sync
  true
end

#sysread

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 203

alias sysread       not_open_for_reading

#sysseek

Alias for #seek.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 231

alias sysseek seek

#syswrite(data)

Alias for #write.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 139

alias syswrite write

#ungetbyte

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 204

alias ungetbyte     not_open_for_reading

#ungetc

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 205

alias ungetc        not_open_for_reading

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 134

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

#write_nonblock(data)

Alias for #write.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/streaming.rb', line 140

alias write_nonblock write