Class: I3::Subscription::SubscriptionConnection
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- I3::Subscription::SubscriptionConnection
- Defined in:
- lib/i3-ipc/subscription.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#post_init ⇒ Object
send subscription to i3.
-
#receive_data(data) ⇒ Object
receive data, parse it and pass on to the user-defined handler.
Class Method Details
.connect(subscription_list, socket_path = nil, &blk) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/i3-ipc/subscription.rb', line 8 def self.connect(subscription_list, socket_path=nil, &blk) new_klass = Class.new(self) new_klass.send(:define_method, :initialize) do @subscription_list = subscription_list @handler = blk end EM.connect socket_path, new_klass end |
Instance Method Details
#post_init ⇒ Object
send subscription to i3
18 19 20 21 |
# File 'lib/i3-ipc/subscription.rb', line 18 def post_init send_data I3::IPC.format(I3::IPC., @subscription_list.to_json) end |
#receive_data(data) ⇒ Object
receive data, parse it and pass on to the user-defined handler
24 25 26 |
# File 'lib/i3-ipc/subscription.rb', line 24 def receive_data(data) @handler.call(self, *I3::IPC.parse_response(data)) if @handler end |