material_raingular-websocket 0.0.3 → 0.0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 512709ed0c5ca9cbad5bf1565e647ffa2e1f0f20
|
4
|
+
data.tar.gz: 30781b4057606d409ab0024d9c4125c0061ccb40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d60e0c9e86a4b439c62098968a871029d25271fff5263d66f5d496c1ed432a2914670a60926d5b7f2dcfebadab2cb7ca5515d4eadc19d4a8e8d5eaae417521a8
|
7
|
+
data.tar.gz: 925a90832b4d2a30f6da21ff3b0432c23fadb81f1a83c38ce19854dd9a0e9aa7e2844e7d496f5811e4110a0d09860f7ff903a8a0165fc0e2ce7326963dc92be9
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "material_raingular/websocket/version"
|
2
2
|
require "material_raingular/websocket/active_record_extension"
|
3
3
|
require "material_raingular/websocket/event_router.rb"
|
4
|
+
require "material_raingular/websocket/emitter.rb"
|
4
5
|
|
5
6
|
module MaterialRaingular
|
6
7
|
module Websocket
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'active_record'
|
3
3
|
require 'websocket-rails'
|
4
|
+
require 'material_raingular/websocket'
|
4
5
|
module EmittableExtension
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
module ClassMethods
|
@@ -8,14 +9,18 @@ module EmittableExtension
|
|
8
9
|
@emittable = true
|
9
10
|
after_destroy :emit_destroyed
|
10
11
|
after_save :emit_changes
|
11
|
-
|
12
|
-
define_method(:emit_changes) {WebsocketRails[websocket_namespace].trigger(:change, websocket_message)}
|
13
|
-
define_method(:websocket_message) {self.to_json}
|
14
|
-
define_method(:destroy_message) {{id: self.id}.to_json}
|
15
|
-
define_method(:websocket_namespace) {self.class.name.underscore.to_sym}
|
12
|
+
def emittable?() @emittable || false end
|
16
13
|
end
|
17
|
-
def emittable?() @emittable || false end
|
18
14
|
end
|
15
|
+
def emit_destroyed
|
16
|
+
MaterialRaingular::Websocket::Emitter[websocket_namespace].publish(:destroy,destroy_message)
|
17
|
+
end
|
18
|
+
def emit_changes
|
19
|
+
MaterialRaingular::Websocket::Emitter[websocket_namespace].publish(:change,websocket_message)
|
20
|
+
end
|
21
|
+
def websocket_message() self.to_json end
|
22
|
+
def destroy_message() {id: self.id}.to_json end
|
23
|
+
def websocket_namespace() self.class.name.underscore.to_sym end
|
19
24
|
def emittable?() self.class.emittable? end
|
20
25
|
end
|
21
26
|
module UserManagerExtension
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MaterialRaingular
|
2
|
+
module Websocket
|
3
|
+
class Emitter
|
4
|
+
class << self
|
5
|
+
def [](channel)
|
6
|
+
new(channel)
|
7
|
+
end
|
8
|
+
def redis() new.redis end
|
9
|
+
def token(channel) new(channel).token end
|
10
|
+
def publish(channel,action,data) new(channel).publish(action,data) end
|
11
|
+
end
|
12
|
+
def redis()
|
13
|
+
@redis ||= Redis.new(WebsocketRails.config.redis_options.reject{|k,v| k.to_sym == :driver})
|
14
|
+
end
|
15
|
+
def token
|
16
|
+
@token ||= redis.hget "websocket_rails.channel_tokens", channel
|
17
|
+
end
|
18
|
+
def publish(action,data)
|
19
|
+
return unless token.present?
|
20
|
+
redis.publish "websocket_rails.events", [action,{data: data,channel: channel, token: token}].to_json
|
21
|
+
end
|
22
|
+
def initialize(channel=nil)
|
23
|
+
self.channel = channel
|
24
|
+
end
|
25
|
+
attr_accessor :channel
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: material_raingular-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/assets/javascripts/material_raingular-websockets.coffee
|
155
155
|
- lib/material_raingular/websocket.rb
|
156
156
|
- lib/material_raingular/websocket/active_record_extension.rb
|
157
|
+
- lib/material_raingular/websocket/emitter.rb
|
157
158
|
- lib/material_raingular/websocket/event_router.rb
|
158
159
|
- lib/material_raingular/websocket/version.rb
|
159
160
|
- material_raingular-websocket.gemspec
|