entangled 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd3064c1f6e0a2646581f73b82460adadd183021
4
- data.tar.gz: a7de74b2b66c782d00af12c4c6ca6788e068b37c
3
+ metadata.gz: 47e523fb330c5b6afaf2a591a5b182cb0f7bb6cd
4
+ data.tar.gz: c2f08b77e3c57ba6f7ac7141b52f7bb4c2cfd286
5
5
  SHA512:
6
- metadata.gz: 1b5c9a3d4f5b9a6b3706653162c143cad14f308d5293041faf42058a0e960d87d32b04ae6e04f31dc6101bffe15449e9ef217f3c50749fd647bb6edf82f0e9cf
7
- data.tar.gz: cc0882bc886ac6aca547bb34eb398731ce8fa912acffa270f80b0d97d774b66efb473d18053b2503731c53339d72f885d9654967a5aa9abc471d247416fbb6db
6
+ metadata.gz: c31e87f3e09508d7c56361af3e828f84da4c0156b7ad9763fe3d888dfc2038c5ef3d1df2dbdbf473f6173707f44625d8da37dbaba59ea6e7d69d3fc2992ae85b
7
+ data.tar.gz: 102f1d094bd646896aade1752327b3edbe0eaea578b1e904572e6ad206d7e701acd369b74950630fc38308a7fc0ab828c4351b4e3f66e1fcc160849d780982e2
data/README.md CHANGED
@@ -165,9 +165,6 @@ Otherwise the channels won't work.
165
165
 
166
166
  If you store your Redis instance in `$redis` or `REDIS` (e.g. in an initializer), Entangled will use that assigned instance so that you can configure Redis just like you're used to. Otherwise, Entangled will instantiate Redis itself and use its default settings.
167
167
 
168
- ### Database
169
- Depending on your app's settings, you might have to increase the pool size in your database.yml configuration file, since every new socket will open a new connection to your database.
170
-
171
168
  ## The Client
172
169
  You will need to configure your client to create Websockets and understand incoming requests on those sockets. In order to use the helper methods for the front end provided by the Entangled Angular library, you must use Angular in your front end. The use of Angular as counterpart of this gem is highly recommended, since its inherent two way data binding complements the real time functionality of this gem nicely.
173
170
 
@@ -321,11 +318,11 @@ The following features are to be implemented next:
321
318
 
322
319
  - Offline capabilities - when client is disconnected, put websocket interactions in a queue and dequeue all once connected again
323
320
  - Support for authentication
321
+ - Support for associations
324
322
  - Remove angular dependencies from bower package (they're currently all being downloaded as well when doing bower install)
325
323
  - On Heroku (maybe in production in general), objects are always in different order depending on their attributes
326
324
  - Add $onChange listener to objects
327
325
  - Add diagram on how it works to Readme
328
- - Reuse open DB connections to reduce pool-size - currently, a new db connection is established for every request, which quickly gets out of hand. Only one DB connection should be opened and maintained per client
329
326
  - Check if Rails 4.0.0 supported too
330
327
 
331
328
  ## Contributing
@@ -27,28 +27,40 @@ module Entangled
27
27
  resources_name.singularize
28
28
  end
29
29
 
30
- # Channel name for collection of resources, used in index
31
- # action
32
- def collection_channel
33
- model.channel
34
- end
35
-
36
30
  # The model for this controller. E.g. Taco for a TacosController
37
31
  def model
38
32
  controller_name.classify.constantize
39
33
  end
40
34
 
35
+ # Grabs @tacos
36
+ def collection
37
+ instance_variable_get(:"@#{resources_name}")
38
+ end
39
+
40
+ # Grabs @taco
41
+ def member
42
+ instance_variable_get(:"@#{resource_name}")
43
+ end
44
+
41
45
  # Channel name for single resource, used in show action
42
46
  def member_channel
43
47
  member.channel
44
48
  end
45
49
 
46
- def collection
47
- instance_variable_get(:"@#{resources_name}")
50
+ # Channel name for collection of resources, used in index
51
+ # action
52
+ def collection_channel
53
+ model.channel
48
54
  end
49
55
 
50
- def member
51
- instance_variable_get(:"@#{resource_name}")
56
+ # Close the connection to the DB so as to
57
+ # not exceed the pool size. Otherwise, too many
58
+ # connections will be leaked and the pool
59
+ # will be exceeded
60
+ def close_db_connection
61
+ if ActiveRecord::Base.connection
62
+ ActiveRecord::Base.connection.close
63
+ end
52
64
  end
53
65
 
54
66
  # Broadcast events to every connected client
@@ -92,6 +104,8 @@ module Entangled
92
104
  tubesock.send_data({
93
105
  resources: collection
94
106
  }.to_json)
107
+
108
+ close_db_connection
95
109
  end
96
110
  end
97
111
 
@@ -131,6 +145,8 @@ module Entangled
131
145
  tubesock.send_data({
132
146
  resource: member
133
147
  }.to_json)
148
+
149
+ close_db_connection
134
150
  end
135
151
  end
136
152
 
@@ -158,6 +174,8 @@ module Entangled
158
174
  resource: member
159
175
  }.to_json)
160
176
  end
177
+
178
+ close_db_connection
161
179
  end
162
180
 
163
181
  # If the controller's action name is 'update', a record should be
@@ -177,6 +195,8 @@ module Entangled
177
195
  resource: member
178
196
  }.to_json)
179
197
  end
198
+
199
+ close_db_connection
180
200
  end
181
201
 
182
202
  # For every other controller action, simply wrap whatever is
@@ -186,6 +206,8 @@ module Entangled
186
206
  else
187
207
  tubesock.onmessage do |m|
188
208
  yield
209
+
210
+ close_db_connection
189
211
  end
190
212
  end
191
213
  end
@@ -94,11 +94,13 @@ module Entangled
94
94
  # to the model's channel or the record's channel
95
95
  # gets the message
96
96
  def publish(action)
97
+ # Publish to model's channel
97
98
  redis.publish(
98
99
  self.class.channel,
99
100
  json(action)
100
101
  )
101
102
 
103
+ # Publish to record#s channel
102
104
  redis.publish(
103
105
  channel,
104
106
  json(action)
@@ -1,3 +1,3 @@
1
1
  module Entangled
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
@@ -6,7 +6,7 @@
6
6
  #
7
7
  default: &default
8
8
  adapter: sqlite3
9
- pool: 5000
9
+ pool: 5
10
10
  timeout: 5000
11
11
 
12
12
  development:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entangled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Charles Hackethal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler