Class: HyperMesh::Connection
Defined Under Namespace
Classes: QueuedMessage
Class Attribute Summary collapse
#acting_user
#backing_record
Class Method Summary
collapse
Instance Method Summary
collapse
#<=>, _synchromesh_scope_args_check, #all, #all=, #all_changed?, #any_changed?, belongs_to, belongs_to_without_reactive_record_add_is_method, #check_permission_with_acting_user, #create, #create_permitted?, #default_scope, #destroy_permitted?, do_not_synchronize, #do_not_synchronize?, do_not_synchronize?, #method_missing, #none_changed?, #only_changed?, pre_synchromesh_default_scope, #pre_synchromesh_method_missing, pre_synchromesh_scope, public_columns_hash, reflect_on_aggregation, reflect_on_all_aggregations, reflect_on_all_associations, reflect_on_association, #scope, #synchromesh_after_change, #synchromesh_after_create, #synchromesh_after_destroy, #unscoped, #update, #update_attribute, #update_permitted?, #view_permitted?
#_react_param_conversion, #abstract_class=, #abstract_class?, #all, #all=, #base_class, #column_names, #columns_hash, #composed_of, #enum, #find, #find_by, #inheritance_column, #inheritance_column=, #method_missing, #model_name, #primary_key, #primary_key=, #scope
#==, #attributes, #changed?, #destroy, #destroyed?, #dup, #errors, #id, #id=, #initialize, #itself, #load, #method_missing, #model_name, #new?, #primary_key, #revert, #save, #saving?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ActiveRecord::Base
Class Attribute Details
.transport ⇒ Object
Returns the value of attribute transport.
80
81
82
|
# File 'lib/synchromesh/connection.rb', line 80
def transport
@transport
end
|
Class Method Details
82
83
84
85
86
|
# File 'lib/synchromesh/connection.rb', line 82
def active
expired.delete_all
refresh_connections if needs_refresh?
all.pluck(:channel).uniq
end
|
.build_tables ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/synchromesh/connection.rb', line 32
def self.build_tables
connection.create_table(:synchromesh_connections, force: true) do |t|
t.string :channel
t.string :session
t.datetime :created_at
t.datetime :expires_at
t.datetime :refresh_at
end
connection.create_table(:synchromesh_queued_messages, force: true) do |t|
t.text :data
t.integer :connection_id
end
end
|
.connect_to_transport(channel, session, root_path) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/synchromesh/connection.rb', line 109
def connect_to_transport(channel, session, root_path)
self.root_path = root_path
if (connection = find_by(channel: channel, session: session))
messages = connection.messages.pluck(:data)
connection.destroy
else
messages = []
end
open(channel)
messages
end
|
.disconnect(channel) ⇒ Object
121
122
123
|
# File 'lib/synchromesh/connection.rb', line 121
def disconnect(channel)
find_by(channel: channel, session: nil).destroy
end
|
.needs_refresh? ⇒ Boolean
63
64
65
|
# File 'lib/synchromesh/connection.rb', line 63
def self.needs_refresh?
exists?(['refresh_at IS NOT NULL AND refresh_at < ?', Time.zone.now])
end
|
.open(channel, session = nil, root_path = nil) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/synchromesh/connection.rb', line 88
def open(channel, session = nil, root_path = nil)
self.root_path = root_path
find_or_create_by(channel: channel, session: session)
rescue Exception => e
binding.pry
end
|
.read(session, root_path) ⇒ Object
102
103
104
105
106
107
|
# File 'lib/synchromesh/connection.rb', line 102
def read(session, root_path)
self.root_path = root_path
where(session: session)
.update_all(expires_at: Time.now + transport.expire_polled_connection_in)
QueuedMessage.for_session(session).destroy_all.pluck(:data)
end
|
.refresh_connections ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/synchromesh/connection.rb', line 133
def refresh_connections
refresh_started_at = Time.zone.now
channels = transport.refresh_channels
next_refresh = refresh_started_at + transport.refresh_channels_every
channels.each do |channel|
find_by(channel: channel, session: nil).update(refresh_at: next_refresh)
end
inactive.delete_all
end
|
.root_path=(path) ⇒ Object
125
126
127
|
# File 'lib/synchromesh/connection.rb', line 125
def root_path=(path)
QueuedMessage.root_path = path if path
end
|
.send_to_channel(channel, data) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/synchromesh/connection.rb', line 95
def send_to_channel(channel, data)
pending_for(channel).each do |connection|
QueuedMessage.create(data: data, synchromesh_connection: connection)
end
transport.send(channel, data) if exists?(channel: channel, session: nil)
end
|
Instance Method Details
#transport ⇒ Object
67
68
69
|
# File 'lib/synchromesh/connection.rb', line 67
def transport
self.class.transport
end
|