entangled 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 586788052b78442155a29cddff0aae0f026aac68
4
- data.tar.gz: 1f57814b47022e219d8748de39cd7c93b88e19b1
3
+ metadata.gz: acd43415d53bc33e46fb87ca6e22b18398048798
4
+ data.tar.gz: 915a582c9aa65fcc3b55abac9a7977a97cccbf0c
5
5
  SHA512:
6
- metadata.gz: e54a0366f09853ce373e4c93959b555bf5fe21beffb801636b558661e4edb09a8a3d1449dc1ec3f318cc0bb061d5608683f90445a6fdb71dfcebba5fc013aa99
7
- data.tar.gz: b99b7c7b1644f38385bf0d85a364822b62ae422f6fb8ac85c291f18994ce7ed1019571012a6a2f10f21fd564105f15aba89b703be5d579fc502b6de19fc680dc
6
+ metadata.gz: 31b7560bb4a78329766122f4a58ba345f60f39364b9324ed0b915214d25504eaf33de5655d6ecb6aa620b35ea223d8a9e2c4f09ab7b9358fcb4e4bb64f277508
7
+ data.tar.gz: 341d2d3360966b6c9edf75561e76a0b5bf64a804f799ebb255d486b7263ae94010cb8a3cabed95562aa356b484572d9316f0e37a53ecd66c41c6083444ab143a
@@ -4,10 +4,6 @@ require 'tubesock/hijack'
4
4
  module Entangled
5
5
  module Controller
6
6
  include Tubesock::Hijack
7
-
8
- module ClassMethods
9
-
10
- end
11
7
 
12
8
  module InstanceMethods
13
9
  include Entangled::Helpers
@@ -31,6 +27,26 @@ module Entangled
31
27
  resources_name.singularize
32
28
  end
33
29
 
30
+ # Channel name for collection of resources, used in index
31
+ # action
32
+ def collection_channel
33
+ resources_name
34
+ end
35
+
36
+ # Channel name for single resource, used in show action
37
+ def member_channel
38
+ instance = member
39
+ "#{resources_name}/#{instance.to_param}"
40
+ end
41
+
42
+ def collection
43
+ instance_variable_get(:"@#{resources_name}")
44
+ end
45
+
46
+ def member
47
+ instance_variable_get(:"@#{resource_name}")
48
+ end
49
+
34
50
  # Broadcast events to every connected client
35
51
  def broadcast(&block)
36
52
  # Use hijack to handle sockets
@@ -60,16 +76,17 @@ module Entangled
60
76
  # ...then @tacos will be broadcast to all connected
61
77
  # clients. The variable name, in this example,
62
78
  # has to be "@tacos"
63
- if instance_variable_get(:"@#{resources_name}")
79
+ if collection
64
80
  redis_thread = Thread.new do
65
- redis.subscribe resources_name do |on|
81
+ redis.subscribe collection_channel do |on|
82
+ # Broadcast messages to all connected clients
66
83
  on.message do |channel, message|
67
84
  tubesock.send_data message
68
85
  end
69
86
 
70
- # Broadcast collection to all connected clients
87
+ # Send message to whoever just subscribed
71
88
  tubesock.send_data({
72
- resources: instance_variable_get(:"@#{resources_name}")
89
+ resources: collection
73
90
  }.to_json)
74
91
  end
75
92
  end
@@ -98,15 +115,18 @@ module Entangled
98
115
 
99
116
  # ...then @taco will be broadcast to all connected clients.
100
117
  # The variable name, in this example, has to be "@taco"
101
- if instance_variable_get(:"@#{resource_name}")
118
+ if member
102
119
  redis_thread = Thread.new do
103
- redis.subscribe "#{resources_name}/#{instance_variable_get(:"@#{resource_name}").id}" do |on|
120
+ redis.subscribe member_channel do |on|
121
+ # Broadcast messages to all connected clients
104
122
  on.message do |channel, message|
105
123
  tubesock.send_data message
106
124
  end
107
125
 
108
- # Broadcast single resource to all connected clients
109
- tubesock.send_data({ resource: instance_variable_get(:"@#{resource_name}") }.to_json)
126
+ # Send message to whoever just subscribed
127
+ tubesock.send_data({
128
+ resource: member
129
+ }.to_json)
110
130
  end
111
131
  end
112
132
 
@@ -122,7 +142,7 @@ module Entangled
122
142
  # happens in the model's callback
123
143
  when 'create'
124
144
  tubesock.onmessage do |m|
125
- params[resource_name.to_sym] = JSON.parse(m).symbolize_keys
145
+ params[resource_name.to_sym] = JSON.parse(m)
126
146
  yield
127
147
  end
128
148
 
@@ -132,7 +152,7 @@ module Entangled
132
152
  # id, created_at, and updated_at should not be included in params.
133
153
  when 'update'
134
154
  tubesock.onmessage do |m|
135
- params[resource_name.to_sym] = JSON.parse(m).except('id', 'created_at', 'updated_at', 'webSocketUrl').symbolize_keys
155
+ params[resource_name.to_sym] = JSON.parse(m)
136
156
  yield
137
157
  end
138
158
 
@@ -150,7 +170,6 @@ module Entangled
150
170
  end
151
171
 
152
172
  def self.included(receiver)
153
- receiver.extend ClassMethods
154
173
  receiver.send :include, InstanceMethods
155
174
  end
156
175
  end
@@ -1,3 +1,3 @@
1
1
  module Entangled
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -4,7 +4,6 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'bourne'
6
6
  require 'byebug'
7
- # require 'factory_girl_rails'
8
7
 
9
8
  # Load support files
10
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
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.12
4
+ version: 0.0.13
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-02 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -9830,6 +9830,7 @@ files:
9830
9830
  - spec/dummy/public/test/controllers/messages_test.js
9831
9831
  - spec/dummy/public/views/messages/index.html
9832
9832
  - spec/dummy/public/views/messages/show.html
9833
+ - spec/dummy/tmp/pids/server.pid
9833
9834
  - spec/models/inclusion_exclusion_spec.rb
9834
9835
  - spec/models/message_spec.rb
9835
9836
  - spec/routing/inclusion_exclusion_routing_spec.rb
@@ -19515,6 +19516,7 @@ test_files:
19515
19516
  - spec/dummy/public/views/messages/show.html
19516
19517
  - spec/dummy/Rakefile
19517
19518
  - spec/dummy/README.rdoc
19519
+ - spec/dummy/tmp/pids/server.pid
19518
19520
  - spec/models/inclusion_exclusion_spec.rb
19519
19521
  - spec/models/message_spec.rb
19520
19522
  - spec/routing/inclusion_exclusion_routing_spec.rb