Class: Kibosh::Session::Streams

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/kibosh/session.rb

Instance Method Summary collapse

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

#hashObject



47
48
49
# File 'lib/kibosh/session.rb', line 47

def hash
  @hash ||= {}
end

#listObject



50
51
52
# File 'lib/kibosh/session.rb', line 50

def list
  @list ||= []
end

#stopObject



44
45
46
# File 'lib/kibosh/session.rb', line 44

def stop
  @list.each { |stream| stream.stop }
end