synth 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/synth/helpers.rb +19 -0
- data/lib/synth/version.rb +1 -1
- data/vendor/assets/javascripts/synth.js.coffee.erb +16 -4
- metadata +6 -6
data/lib/synth/helpers.rb
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
module Synth
|
2
2
|
module Helpers
|
3
3
|
extend self
|
4
|
+
|
5
|
+
def endpoints
|
6
|
+
routes = ::Rails.application.routes.routes.named_routes.keep_if {|name, route|
|
7
|
+
route.required_defaults.has_key?(:action) && route.required_defaults[:action] == 'show'
|
8
|
+
}.map {|name, route|
|
9
|
+
[
|
10
|
+
route.required_defaults[:controller].singularize.to_sym,
|
11
|
+
route.path.spec.to_s.gsub('(.:format)', '.:format').gsub(/\(.*\)/, ''),
|
12
|
+
route.parts.size
|
13
|
+
]
|
14
|
+
}.sort {|a,b| a.last <=> b.last }
|
15
|
+
|
16
|
+
endpoints = {}
|
17
|
+
for route in routes
|
18
|
+
endpoints[route[0]] ||= route[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
endpoints
|
22
|
+
end
|
4
23
|
end
|
5
24
|
end
|
data/lib/synth/version.rb
CHANGED
@@ -3,11 +3,17 @@
|
|
3
3
|
|
4
4
|
class Synth
|
5
5
|
|
6
|
-
@
|
6
|
+
@endpoints = {
|
7
|
+
<% for route, endpoint in Synth::Helpers.endpoints %>
|
8
|
+
<%= "#{route}: '#{endpoint}'" %>
|
9
|
+
<% end %>
|
10
|
+
}
|
11
|
+
|
12
|
+
@connect = ->
|
7
13
|
@connection = new WebSocket 'ws://localhost:1337', 'synth'
|
8
14
|
|
9
15
|
@subscribe = ->
|
10
|
-
@subscriptions = ([ $(e).attr('class'), $(e).attr('data-id') ].join('-') for e in $('[class][data-id]')).uniq()
|
16
|
+
@subscriptions = ([ $(e).attr('class').split(" ")[0], $(e).attr('data-id') ].join('-') for e in $('[class][data-id]')).uniq()
|
11
17
|
@connection.send JSON.stringify(@subscriptions)
|
12
18
|
|
13
19
|
@log = (msg) ->
|
@@ -24,14 +30,20 @@ $(document).on 'synth:subscribe', ->
|
|
24
30
|
|
25
31
|
$ ->
|
26
32
|
|
27
|
-
Synth.
|
33
|
+
Synth.connect()
|
28
34
|
|
29
35
|
Synth.connection.onopen = ->
|
30
36
|
$(document).trigger 'synth:subscribe'
|
31
37
|
Synth.log 'Connected'
|
32
38
|
|
33
39
|
Synth.connection.onmessage = (msg) ->
|
34
|
-
|
40
|
+
rawData = JSON.parse(msg.data)
|
41
|
+
modelAndId = rawData[0].split '-'
|
42
|
+
model = modelAndId[0]
|
43
|
+
id = modelAndId[1]
|
44
|
+
updatedAt = parseInt(rawData[1])
|
45
|
+
$(document).trigger 'synth:update', [ model, id, updatedAt ]
|
46
|
+
Synth.log 'Updated: ' + [ model, id, updatedAt ].join(' ')
|
35
47
|
|
36
48
|
Synth.connection.onclose = ->
|
37
49
|
Synth.log 'Disconnected'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redis
|
17
|
-
requirement: &
|
17
|
+
requirement: &70300189145360 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70300189145360
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: redis-namespace
|
28
|
-
requirement: &
|
28
|
+
requirement: &70300189144920 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70300189144920
|
37
37
|
description: Real-time for Rails
|
38
38
|
email:
|
39
39
|
- synth@stackd.com
|