acts_as_realtime 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/acts_as_realtime.rb +39 -6
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDdlNGExYmE4MTQyYWQzOWFhMTYyZGViZDFmZTEyYTk0NmYyYTdiMQ==
4
+ OGE2Y2Y4ZTNkMzc1Njk4N2FlNWNhMTI3MWNjNDhhMzljZTYyMWJmYw==
5
5
  data.tar.gz: !binary |-
6
- NDM2NmJlM2E4M2M3YTA3MDAxNjdiMDEyOWUxZGUzZDJlMzdmYTAyOA==
6
+ Yjg2YWU0N2M1ZWUyYzBmMTY5MTdmMmNmOGZiNDlhMzVmNjU2OTk4ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDkyMmFjMDhmNThhNGE5OTc5YzZjZGRiYTBlOWU2NWFkYjZjNzdhMmQ0NmQ5
10
- NzVhMDZmNWM0NTA5Y2FkMzYyYjhlZDc5M2NlNGQzYWY5ZjJkMzM4OTVhYTU0
11
- YjY3OGRlMWYzZjQ5MGYyN2U1OTQxNDYzYTc3ZTA1OTkxNzQzZWU=
9
+ Y2E4MGYwNDQ4MjU1YmJkNDFkNzhmNTA2MjA3YzVkNTAxNjAyMGI0YmFjN2Q5
10
+ ZWJiM2U2YTJmZTY4MDIyODIzZDNjYWEwZjQwOWQ0NzkwNTZhNThhZGQ3YjFk
11
+ Y2ViMTMwNzI2MzRiNzQ5MDA3YTJmMWNlZWMwNzk5OWUxMzgyOGQ=
12
12
  data.tar.gz: !binary |-
13
- YTg2NGZlZDE1NWM4MzE4MTRiMmMxYTg4ZDM4ZDA2NGY0Zjg2YzYxMDI0OTU2
14
- OTI3ZDdmNDYxNTUzYzk0NWVhYzk4MDFmY2E1NmQ1NzY4ZmZjZDYxNDM2ODEx
15
- YjU1NzIyMmU1ZDk2Nzc4OWJlYzZjODZlYjY4NDAyODZhMzlhZDY=
13
+ N2M0NGRkNTVhYmJhZWI0YzcwMTk3MTgxY2EyNDE1YjBhMmU5NzMzMDRjMDAy
14
+ YmI3NTg2Y2I1YjFiYzU1MjQwYzc5YmRjMGM3NjY0Y2M3YmIxMWYxNzhkYTAz
15
+ ZmZlODc2NGYwZDc4NjZjOGJjZTRjYTY5ZDc2ZGI0MDQ4MzJjMTQ=
@@ -3,7 +3,7 @@ require 'em-websocket'
3
3
 
4
4
  module ActsAsRealTime
5
5
 
6
- class << self; attr_accessor :ws, :channel; end
6
+ class << self; attr_accessor :ws, :channel, :mod_app, :html, :port, :selector, :host, :insert_method; end
7
7
 
8
8
  def self.startup_web_socket_server
9
9
  Thread.new {
@@ -19,6 +19,7 @@ module ActsAsRealTime
19
19
 
20
20
  ws.onmessage { |msg|
21
21
  #@channel.push "<#{sid}>: #{msg}"
22
+ puts msg
22
23
  }
23
24
 
24
25
  ws.onclose {
@@ -47,20 +48,51 @@ module ActsAsRealTime
47
48
  end
48
49
 
49
50
  module ClassMethods
50
- def acts_as_realtime &blk
51
- puts "ESTA GEMARA HARA QUE LAS APLICACIONES DE RAILS REVOLUCIONEN INCREIBLEMENTE"
52
51
 
53
- yield ActsAsRealTime.ws, ActsAsRealTime.channel if block_given?
52
+ def acts_as_realtime(config_params = {selector: nil, insertion_method: 'prepend'}, &blk)
54
53
 
54
+ =begin
55
+ Se había manejado cómo posible solución el manejar un token(*-*)
56
+ para interporlar los valores de los registros que se estan creando, cómo
57
+ por ejemplo el nombre de un usuario.
58
+
59
+ La idea consistia que el nombre del campo que se quiere interpolar debe de ir entre el token
60
+ identificador(*-*) en el html que sea pasado a la gema, para se parseado(interpolado) por la gema.
61
+ Ej:
62
+
63
+ html = "<tr><td><div class=" + '"prueba1"' + " > *-*#{'nombre'}*-* </div></td><td>R</td><td>o</td><td>R</td></tr>"
64
+
65
+ Esta solución puede causar problemas futuros, es por eso que se busco otra solución, que es el código
66
+ actual, esto se deja comentado por si se necesitara usar despues
67
+
68
+
69
+
70
+ start_index = html.index("*-*")
71
+ sub_html = html[start_index+3..-1]
72
+ finish_index = sub_html.index('*-*') + 2
73
+ attr = sub_html[0..finish_index-3]
74
+
75
+
76
+ =end
77
+
78
+ #Se define el método update_index en lo modelos que se ejecute el método acts_as_real_time
55
79
  ActiveRecord::Base.class_eval {
56
- def update_index
57
- puts "SI SE EJECUTA EL UPDATE INDEX-----------++++++++++++++++-------------"
80
+ define_method(:update_index) do
81
+
82
+ #eval("html[start_index..finish_index] = #{attr}") Esta instrucción se usaba para la solución que se planteó arriba
83
+
84
+ res_yield = yield ActsAsRealTime.ws, ActsAsRealTime.channel, self if block_given?
85
+ ActsAsRealTime.mod_app, ActsAsRealTime.html = res_yield[0], res_yield[1]
86
+ ActsAsRealTime.mod_app::Application.config.chanel = ActsAsRealTime::channel
87
+ ActsAsRealTime.mod_app::Application.config.chanel.push "$('#{config_params[:selector]}').#{config_params[:insertion_method]}('#{ActsAsRealTime.html}');"
58
88
  end
59
89
  after_create :update_index
60
90
  }
61
91
  end
62
92
  end
63
93
 
94
+ =begin
95
+ Estos métodos no se usa actualmente, se deja comentado cómo ejemplo para modificaciones o mejoras futuras
64
96
  def self.define_adders_methods app
65
97
  eval "#{app}::Aplication.class_eval {" +
66
98
  "define_method(:save_communication_variables, :ws, :channel){" +
@@ -69,6 +101,7 @@ module ActsAsRealTime
69
101
  "}" +
70
102
  "}"
71
103
  end
104
+ =end
72
105
  end
73
106
 
74
107
  ActiveRecord::Base.send :include, ActsAsRealTime
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
4
+ version: 0.0.5
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-04 00:00:00.000000000 Z
11
+ date: 2015-03-05 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
@@ -18,7 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/acts_as_realtime.rb
21
- homepage: http://rubygems.org/gems/acts_as_realtime
21
+ homepage: https://github.com/rolandoivan23/acts_as_realtime
22
22
  licenses:
23
23
  - MIT
24
24
  metadata: {}