Class: Syncro::Client
- Inherits:
-
SuperModel::Base
- Object
- SuperModel::Base
- Syncro::Client
- Includes:
- SuperModel::Marshal::Model, SuperModel::RandomID, SuperModel::Redis::Model
- Defined in:
- lib/syncro/client.rb,
lib/syncro/marshal.rb,
lib/syncro/redis/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_scribe(scribe, &block) ⇒ Object
- #connect(connection) ⇒ Object
- #connected? ⇒ Boolean
- #connection ⇒ Object
- #disconnect ⇒ Object
- #receive_data(data) ⇒ Object
- #receive_message(data) ⇒ Object
- #send_message(message) ⇒ Object
- #serializable_hash(options = {}) ⇒ Object
- #sync(&block) ⇒ Object
- #to_s ⇒ Object
Class Method Details
.for(uid) ⇒ Object
6 7 8 |
# File 'lib/syncro/client.rb', line 6 def for(uid) find_or_create_by_uid(uid) end |
Instance Method Details
#add_scribe(scribe, &block) ⇒ Object
28 29 30 |
# File 'lib/syncro/client.rb', line 28 def add_scribe(scribe, &block) app.add_scribe(scribe, &block) end |
#connect(connection) ⇒ Object
17 18 19 |
# File 'lib/syncro/client.rb', line 17 def connect(connection) self.connection = connection end |
#connected? ⇒ Boolean
13 14 15 |
# File 'lib/syncro/client.rb', line 13 def connected? !!self.connection end |
#connection ⇒ Object
13 14 15 |
# File 'lib/syncro/redis/client.rb', line 13 def connection self.class.connections[self.id] end |
#disconnect ⇒ Object
21 22 |
# File 'lib/syncro/client.rb', line 21 def disconnect end |
#receive_data(data) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/syncro/client.rb', line 32 def receive_data(data) buffer << data buffer..each do |msg| (msg) end end |
#receive_message(data) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/syncro/client.rb', line 39 def (data) = begin case data when String Protocol::Message.fromJSON(data) when Protocol::Message data else Protocol::Message.new(data) end end app.call() end |
#send_message(message) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/syncro/client.rb', line 53 def () return unless connected? if connection.respond_to?(:send_message) connection.() elsif connection.respond_to?(:send_data) connection.send_data(.serialize) else connection.write(.serialize) end end |
#serializable_hash(options = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/syncro/client.rb', line 68 def serializable_hash( = {}) [:except] ||= [] [:except] << :connection super() end |
#sync(&block) ⇒ Object
24 25 26 |
# File 'lib/syncro/client.rb', line 24 def sync(&block) app.sync(&block) end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/syncro/client.rb', line 64 def to_s (uid || id).to_s end |