acts_as_realtime 0.0.3 → 0.0.4
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 +8 -8
- data/lib/acts_as_realtime.rb +72 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
ZDdlNGExYmE4MTQyYWQzOWFhMTYyZGViZDFmZTEyYTk0NmYyYTdiMQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NDM2NmJlM2E4M2M3YTA3MDAxNjdiMDEyOWUxZGUzZDJlMzdmYTAyOA==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
NDkyMmFjMDhmNThhNGE5OTc5YzZjZGRiYTBlOWU2NWFkYjZjNzdhMmQ0NmQ5
|
|
10
|
+
NzVhMDZmNWM0NTA5Y2FkMzYyYjhlZDc5M2NlNGQzYWY5ZjJkMzM4OTVhYTU0
|
|
11
|
+
YjY3OGRlMWYzZjQ5MGYyN2U1OTQxNDYzYTc3ZTA1OTkxNzQzZWU=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
YTg2NGZlZDE1NWM4MzE4MTRiMmMxYTg4ZDM4ZDA2NGY0Zjg2YzYxMDI0OTU2
|
|
14
|
+
OTI3ZDdmNDYxNTUzYzk0NWVhYzk4MDFmY2E1NmQ1NzY4ZmZjZDYxNDM2ODEx
|
|
15
|
+
YjU1NzIyMmU1ZDk2Nzc4OWJlYzZjODZlYjY4NDAyODZhMzlhZDY=
|
data/lib/acts_as_realtime.rb
CHANGED
|
@@ -1,13 +1,82 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
require 'em-websocket'
|
|
3
|
+
|
|
1
4
|
module ActsAsRealTime
|
|
5
|
+
|
|
6
|
+
class << self; attr_accessor :ws, :channel; end
|
|
7
|
+
|
|
8
|
+
def self.startup_web_socket_server
|
|
9
|
+
Thread.new {
|
|
10
|
+
begin
|
|
11
|
+
EventMachine.run {
|
|
12
|
+
@channel = EM::Channel.new
|
|
13
|
+
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8092, :debug => true) do |ws|
|
|
14
|
+
@ws = ws
|
|
15
|
+
#RoRRT::Application.save_communication_variables @channel, ws
|
|
16
|
+
ws.onopen {
|
|
17
|
+
sid = @channel.subscribe { |msg| ws.send msg }
|
|
18
|
+
#@channel.push "#{sid} connected!"
|
|
19
|
+
|
|
20
|
+
ws.onmessage { |msg|
|
|
21
|
+
#@channel.push "<#{sid}>: #{msg}"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ws.onclose {
|
|
25
|
+
@channel.unsubscribe(sid)
|
|
26
|
+
#@channel.push "<#{sid}>: Closed"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
puts "Web socket server started"
|
|
32
|
+
}
|
|
33
|
+
rescue => e
|
|
34
|
+
puts e.message
|
|
35
|
+
end
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#Este while es para esperar a que el hilo asigne las variables del socket y del canal
|
|
39
|
+
while (@channel.nil? and @ws.nil?); end
|
|
40
|
+
[@ws, @channel]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
ws, channel = ActsAsRealTime::startup_web_socket_server
|
|
44
|
+
|
|
2
45
|
def self.included(base)
|
|
3
46
|
base.send :extend, ClassMethods
|
|
4
47
|
end
|
|
48
|
+
|
|
5
49
|
module ClassMethods
|
|
6
|
-
def acts_as_realtime
|
|
50
|
+
def acts_as_realtime &blk
|
|
7
51
|
puts "ESTA GEMARA HARA QUE LAS APLICACIONES DE RAILS REVOLUCIONEN INCREIBLEMENTE"
|
|
52
|
+
|
|
53
|
+
yield ActsAsRealTime.ws, ActsAsRealTime.channel if block_given?
|
|
54
|
+
|
|
55
|
+
ActiveRecord::Base.class_eval {
|
|
56
|
+
def update_index
|
|
57
|
+
puts "SI SE EJECUTA EL UPDATE INDEX-----------++++++++++++++++-------------"
|
|
58
|
+
end
|
|
59
|
+
after_create :update_index
|
|
60
|
+
}
|
|
8
61
|
end
|
|
9
62
|
end
|
|
63
|
+
|
|
64
|
+
def self.define_adders_methods app
|
|
65
|
+
eval "#{app}::Aplication.class_eval {" +
|
|
66
|
+
"define_method(:save_communication_variables, :ws, :channel){" +
|
|
67
|
+
"config.chanel = channel" +
|
|
68
|
+
"config.ws = ws" +
|
|
69
|
+
"}" +
|
|
70
|
+
"}"
|
|
71
|
+
end
|
|
10
72
|
end
|
|
11
73
|
|
|
12
|
-
|
|
13
|
-
|
|
74
|
+
ActiveRecord::Base.send :include, ActsAsRealTime
|
|
75
|
+
=begin
|
|
76
|
+
eval "RoRRT::Aplication.class_eval {" +
|
|
77
|
+
"define_method(:save_communication_variables, :ws, :channel){" +
|
|
78
|
+
"config.chanel = channel" +
|
|
79
|
+
"config.ws = ws" +
|
|
80
|
+
"}" +
|
|
81
|
+
"}"
|
|
82
|
+
=end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acts_as_realtime
|
|
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
|
- Rolando Vazquez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-11-
|
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Gem for add realtime functionality for ruby on rails apps, it use em-websocket
|
|
14
14
|
gem sor use websockets and channels
|