real_time_rails 0.0.4 → 0.0.5

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.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Beta Usage
22
22
 
23
23
  The gem is now loading and running correctly in the project. Still some bugs to iron out.
24
24
 
25
- To start the websocket server just run the websocket_server.rb ruby script.
25
+ To start the websocket server just run the "real\_time_rails" executable. There is not any configuration options yet, but they should be added soon.
26
26
 
27
27
  Add to your Gemfile
28
28
 
@@ -36,10 +36,10 @@ then in your view that you want a real time update. At this point partial paths
36
36
 
37
37
  `render_real_time partial: '/test/test', locals: {chats: @chats}`
38
38
 
39
- I still have a lot of debugging stuff in the view and javascript wrapper so ignore those for now.
40
-
41
39
 
42
40
  History
43
41
  ----------
44
42
 
45
- 0.0.4 Adding RealTimeRails server executable.
43
+ 0.0.5 Added delete updates
44
+
45
+ 0.0.4 Adding RealTimeRails server executable. start it with "real\_time_rails"
data/bin/real_time_rails CHANGED
@@ -112,6 +112,9 @@ EventMachine.run {
112
112
  command = JSON.parse(data)
113
113
  puts command
114
114
  case command["command"]
115
+ when "delete1"
116
+ channels = find_channels_by_id(command["model"], command["id"])
117
+ channels.each{|c| c.push "delete"}
115
118
  when "update1"
116
119
  channels = find_channels_by_id(command["model"], command["id"])
117
120
  channels.each{|c| c.push "update"}
@@ -5,13 +5,13 @@ module RealTimeRails
5
5
  #after every save send notification to the realtimerails socket server.
6
6
  def self.included(klass)
7
7
  klass.send :after_save, :send_rtr_update
8
+ klass.send :after_destroy, :send_rtr_destroy
8
9
  end
9
10
 
10
11
  private
11
12
 
12
13
  def send_rtr_update
13
14
  # TODO figure out why i have to make 2 connections to send 2 messages instead of just one connection.
14
-
15
15
  mySock = TCPSocket::new('127.0.0.1', 2000)
16
16
  mySock.puts("{\"command\":\"update1\",\"model\":\"#{self.class.name}\",\"id\":\"#{self.id}\"}")
17
17
  mySock.close
@@ -20,6 +20,18 @@ module RealTimeRails
20
20
  mySock.puts("{\"command\":\"updateall\",\"model\":\"#{self.class.name}\"}")
21
21
  mySock.close
22
22
  end
23
+
24
+
25
+ def send_rtr_destroy
26
+ # TODO figure out why i have to make 2 connections to send 2 messages instead of just one connection.
27
+ mySock = TCPSocket::new('127.0.0.1', 2000)
28
+ mySock.puts("{\"command\":\"delete1\",\"model\":\"#{self.class.name}\",\"id\":\"#{self.id}\"}")
29
+ mySock.close
30
+
31
+ mySock = TCPSocket::new('127.0.0.1', 2000)
32
+ mySock.puts("{\"command\":\"updateall\",\"model\":\"#{self.class.name}\"}")
33
+ mySock.close
34
+ end
23
35
  end
24
36
 
25
37
  end
@@ -85,7 +85,10 @@ module RealTimeRails
85
85
  def js_start_websocket
86
86
  "
87
87
  ws_#{@id} = new WebSocket('ws://localhost:8080');
88
- ws_#{@id}.onmessage = function(evt) { if(evt.data=='update'){real_time_update_#{@id}()}else{alert(evt.data)}; };
88
+ ws_#{@id}.onmessage = function(evt) {
89
+ if(evt.data=='update'){real_time_update_#{@id}()};
90
+ if(evt.data=='delete'){real_time_delete_#{@id}()};
91
+ };
89
92
  ws_#{@id}.onclose = function() { };
90
93
  ws_#{@id}.onopen = function() {
91
94
  ws_#{@id}.send('#{@websocket_options.to_json}');
@@ -106,6 +109,9 @@ module RealTimeRails
106
109
  def js_remote_function
107
110
  "function real_time_update_#{@id}(){
108
111
  #{remote_function(remote_f_options)}
112
+ }
113
+ function real_time_delete_#{@id}(){
114
+ $('##{@id}').remove;
109
115
  }"
110
116
  end
111
117
 
@@ -1,5 +1,5 @@
1
1
  module RealTimeRails
2
2
 
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
 
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: real_time_rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kelly Mahan