Class: Kibosh::Sessions
- Inherits:
-
Object
- Object
- Kibosh::Sessions
- Includes:
- Exceptions
- Defined in:
- lib/kibosh/sessions.rb
Instance Method Summary collapse
- #<<(session) ⇒ Object
- #[](sid) ⇒ Object
- #hash ⇒ Object
-
#initialize(env) ⇒ Sessions
constructor
A new instance of Sessions.
- #list ⇒ Object
Constructor Details
#initialize(env) ⇒ Sessions
Returns a new instance of Sessions.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kibosh/sessions.rb', line 5 def initialize env class << env['async.callback'].receiver.backend def stop @stop_callback.call if @stop_callback super end def stop_callback &block @stop_callback = block end end env['async.callback'].receiver.backend.stop_callback do @list.each { |stream| stream.stop } end end |
Instance Method Details
#<<(session) ⇒ Object
33 34 35 36 37 |
# File 'lib/kibosh/sessions.rb', line 33 def << session raise Error.new InternalServerError, "session with sid #{session.sid} already defined", session if hash[session.sid] hash[session.sid] = session list << session end |
#[](sid) ⇒ Object
29 30 31 |
# File 'lib/kibosh/sessions.rb', line 29 def [] sid hash[sid] or raise Error.new ItemNotFound, "no session with sid #{sid}" end |
#hash ⇒ Object
21 22 23 |
# File 'lib/kibosh/sessions.rb', line 21 def hash @hash ||= {} end |
#list ⇒ Object
25 26 27 |
# File 'lib/kibosh/sessions.rb', line 25 def list @list ||= [] end |