Class: Kibosh::Session::Streams
- Inherits:
-
Object
- Object
- Kibosh::Session::Streams
- Includes:
- Exceptions
- Defined in:
- lib/kibosh/session.rb
Instance Method Summary collapse
- #<<(stream) ⇒ Object
- #[](key) ⇒ Object
- #delete(stream) ⇒ Object
- #hash ⇒ Object
-
#initialize(session) ⇒ Streams
constructor
A new instance of Streams.
- #list ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(session) ⇒ Streams
Returns a new instance of Streams.
41 42 43 |
# File 'lib/kibosh/session.rb', line 41 def initialize session @session = session end |
Instance Method Details
#<<(stream) ⇒ Object
71 72 73 74 75 |
# File 'lib/kibosh/session.rb', line 71 def << stream raise "hell #{stream.id}" if hash[stream.id] hash[stream.id] = stream list << stream end |
#[](key) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kibosh/session.rb', line 53 def [] key case key when Kibosh::Request if key['to'] raise "implement new stream" else if key['stream'] || list.length != 1 self[ key['stream'] ] else list.first end end else stream = hash[key] raise Kibosh::Error.new ItemNotFound, "no stream with id '#{key}'", @session if !stream stream end end |
#delete(stream) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/kibosh/session.rb', line 76 def delete stream raise "hell #{stream.id}" if !hash[stream.id] raise "hell #{stream.id}" if !list.include? stream hash.delete stream.id list.delete stream end |
#hash ⇒ Object
47 48 49 |
# File 'lib/kibosh/session.rb', line 47 def hash @hash ||= {} end |
#list ⇒ Object
50 51 52 |
# File 'lib/kibosh/session.rb', line 50 def list @list ||= [] end |
#stop ⇒ Object
44 45 46 |
# File 'lib/kibosh/session.rb', line 44 def stop @list.each { |stream| stream.stop } end |