Class: Pollen::Pusher
- Inherits:
-
Object
- Object
- Pollen::Pusher
- Defined in:
- lib/pollen/pusher.rb
Instance Method Summary collapse
- #close ⇒ Object
- #comment ⇒ Object
-
#initialize(socket) ⇒ Pusher
constructor
A new instance of Pusher.
- #push(payload, event:) ⇒ Object
- #write_headers ⇒ Object
Constructor Details
#initialize(socket) ⇒ Pusher
Returns a new instance of Pusher.
7 8 9 |
# File 'lib/pollen/pusher.rb', line 7 def initialize(socket) @socket = socket end |
Instance Method Details
#close ⇒ Object
24 25 26 27 |
# File 'lib/pollen/pusher.rb', line 24 def close write_last_chunk socket_close end |
#comment ⇒ Object
16 17 18 |
# File 'lib/pollen/pusher.rb', line 16 def comment write_chunk [':', "\n"].compact.join("\n") end |
#push(payload, event:) ⇒ Object
20 21 22 |
# File 'lib/pollen/pusher.rb', line 20 def push(payload, event:) write_chunk ["event:#{event}", payload ? "data:#{payload}" : nil, "\n"].compact.join("\n") end |
#write_headers ⇒ Object
11 12 13 14 |
# File 'lib/pollen/pusher.rb', line 11 def write_headers socket_puts headers.join("\n") socket_puts end |