Class: Rack::Stream::App

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/stream/app.rb

Defined Under Namespace

Classes: StateConstraintError, UnsupportedServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ App

Returns a new instance of App.



18
19
20
21
22
# File 'lib/rack/stream/app.rb', line 18

def initialize(app, options={})
  @app       = app
  @state     = :new
  @callbacks = Hash.new {|h,k| h[k] = []}
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



16
17
18
# File 'lib/rack/stream/app.rb', line 16

def headers
  @headers
end

#stateObject (readonly)

The state of the connection :new :open :closed



11
12
13
# File 'lib/rack/stream/app.rb', line 11

def state
  @state
end

#statusObject

Returns the value of attribute status.



16
17
18
# File 'lib/rack/stream/app.rb', line 16

def status
  @status
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
# File 'lib/rack/stream/app.rb', line 24

def call(env)
  EM.next_tick {open!(env)}
  ASYNC_RESPONSE
end

#chunk(*chunks) ⇒ Object Also known as: <<



39
40
41
42
43
44
# File 'lib/rack/stream/app.rb', line 39

def chunk(*chunks)
  require_state :new, :open
  run_callbacks(:chunk, chunks) {|mutated_chunks|
    @handler.chunk(*mutated_chunks)
  }
end

#close(flush = true) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rack/stream/app.rb', line 47

def close(flush = true)
  require_state :open

  # run in the next tick since it's more natural to call #chunk right
  # before #close
  EM.next_tick {
    run_callbacks(:close) {
      @state = :closed
      @handler.close!(flush)
    }
  }
end

#closed?Boolean

Returns:

  • (Boolean)


67
# File 'lib/rack/stream/app.rb', line 67

def closed?;  @state == :closed  end

#errored?Boolean

Returns:

  • (Boolean)


68
# File 'lib/rack/stream/app.rb', line 68

def errored?; @state == :errored end

#new?Boolean

Returns:

  • (Boolean)


65
# File 'lib/rack/stream/app.rb', line 65

def new?;     @state == :new     end

#open?Boolean

Returns:

  • (Boolean)


66
# File 'lib/rack/stream/app.rb', line 66

def open?;    @state == :open    end

#stream_transportString

Returns name of the handler for this request.

Returns:

  • (String)

    name of the handler for this request



61
62
63
# File 'lib/rack/stream/app.rb', line 61

def stream_transport
  @handler and @handler.class.name.split('::').last
end