Class: Kibosh::Session::Stream
- Inherits:
-
Object
- Object
- Kibosh::Session::Stream
- Defined in:
- lib/kibosh/session/stream.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Response
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#from ⇒ Object
Returns the value of attribute from.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#secure ⇒ Object
Returns the value of attribute secure.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #abort ⇒ Object
- #body ⇒ Object
- #body=(body) ⇒ Object
- #close ⇒ Object
- #id ⇒ Object
-
#initialize(object, request, response) ⇒ Stream
constructor
A new instance of Stream.
- #lock(body) ⇒ Object
- #ready! ⇒ Object
- #respond ⇒ Object
- #stop ⇒ Object
- #terminate(request, response) ⇒ Object
- #terminate! ⇒ Object
Constructor Details
#initialize(object, request, response) ⇒ Stream
Returns a new instance of Stream.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kibosh/session/stream.rb', line 15 def initialize object, request, response case object when Kibosh::Session::Stream other = object @session = other.session @to = other.to @route = other.route @driver = other.driver session.streams << self when Kibosh::Session session = object @session = session @to = request["to"] @route = request["route"] @driver = request.driver @session, @to, @route session.streams << self response.stream = self yield connect request, response.extend(Response) else raise "hell" end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/kibosh/session/stream.rb', line 12 def connection @connection end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
12 13 14 |
# File 'lib/kibosh/session/stream.rb', line 12 def driver @driver end |
#from ⇒ Object
Returns the value of attribute from.
13 14 15 |
# File 'lib/kibosh/session/stream.rb', line 13 def from @from end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
12 13 14 |
# File 'lib/kibosh/session/stream.rb', line 12 def route @route end |
#secure ⇒ Object
Returns the value of attribute secure.
13 14 15 |
# File 'lib/kibosh/session/stream.rb', line 13 def secure @secure end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
12 13 14 |
# File 'lib/kibosh/session/stream.rb', line 12 def session @session end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
12 13 14 |
# File 'lib/kibosh/session/stream.rb', line 12 def to @to end |
Instance Method Details
#abort ⇒ Object
108 109 110 |
# File 'lib/kibosh/session/stream.rb', line 108 def abort session.streams.delete self end |
#body ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kibosh/session/stream.rb', line 45 def body @body ||= begin document = Nokogiri::XML::Document.new body = document.create_element("body") # puts "new body #{body.object_id}" body["xmlns"] = 'http://jabber.org/protocol/httpbind' body["stream"] = id document.root = body end # puts "current body #{@body.object_id}" # raise "hell" if @body["sent"] @body end |
#body=(body) ⇒ Object
60 61 62 63 64 |
# File 'lib/kibosh/session/stream.rb', line 60 def body= body raise "hell" if @body || !body.nil? # puts "set body #{body.object_id}" @body = body end |
#close ⇒ Object
103 104 105 106 |
# File 'lib/kibosh/session/stream.rb', line 103 def close raise "implement" abort end |
#id ⇒ Object
99 100 101 |
# File 'lib/kibosh/session/stream.rb', line 99 def id @id ||= ('%16.16f' % rand)[2..-1] end |
#lock(body) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/kibosh/session/stream.rb', line 66 def lock body # puts "lock? #{body.object_id} #{@body.object_id} (#{body['sent']})" # raise "hell" if body['sent'] if body.object_id == @body.object_id # puts "locking #{@body}" @body = nil else # puts "not locking #{@body}" end end |
#ready! ⇒ Object
81 82 83 |
# File 'lib/kibosh/session/stream.rb', line 81 def ready! respond end |
#respond ⇒ Object
77 78 79 |
# File 'lib/kibosh/session/stream.rb', line 77 def respond @body = @session.respond @body end |
#stop ⇒ Object
38 39 40 41 42 43 |
# File 'lib/kibosh/session/stream.rb', line 38 def stop # FIX body["type"] = "terminate" body["condition"] = "system-shutdown" respond end |
#terminate(request, response) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/kibosh/session/stream.rb', line 85 def terminate request, response document = Nokogiri::XML::Document.new body = document.create_element("body") body["xmlns"] = 'http://jabber.org/protocol/httpbind' # body["stream"] = id (?) response.body = document.root = body abort response end |
#terminate! ⇒ Object
95 96 97 |
# File 'lib/kibosh/session/stream.rb', line 95 def terminate! abort end |