synth 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.
- data/lib/synth/helpers.rb +0 -19
- data/lib/synth/version.rb +1 -1
- data/vendor/assets/javascripts/synth.js.coffee.erb +11 -14
- metadata +6 -6
data/lib/synth/helpers.rb
CHANGED
@@ -1,24 +1,5 @@
|
|
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
|
23
4
|
end
|
24
5
|
end
|
data/lib/synth/version.rb
CHANGED
@@ -3,12 +3,6 @@
|
|
3
3
|
|
4
4
|
class Synth
|
5
5
|
|
6
|
-
@endpoints = {
|
7
|
-
<% for route, endpoint in Synth::Helpers.endpoints %>
|
8
|
-
<%= "#{route}: '#{endpoint}'" %>
|
9
|
-
<% end %>
|
10
|
-
}
|
11
|
-
|
12
6
|
@connect = ->
|
13
7
|
@connection = new WebSocket 'ws://localhost:1337', 'synth'
|
14
8
|
|
@@ -16,11 +10,20 @@ class Synth
|
|
16
10
|
@subscriptions = ([ $(e).attr('class').split(" ")[0], $(e).attr('data-id') ].join('-') for e in $('[class][data-id]')).uniq()
|
17
11
|
@connection.send JSON.stringify(@subscriptions)
|
18
12
|
|
13
|
+
@update = (msg) ->
|
14
|
+
rawData = JSON.parse(msg.data)
|
15
|
+
modelAndId = rawData[0].split '-'
|
16
|
+
model = modelAndId[0]
|
17
|
+
id = modelAndId[1]
|
18
|
+
updatedAt = parseInt(rawData[1])
|
19
|
+
$(document).trigger 'synth:update', [ model, id, updatedAt ]
|
20
|
+
@log 'synth:update triggered: ' + [ model, id, updatedAt ].join(' ')
|
21
|
+
|
19
22
|
@log = (msg) ->
|
20
23
|
console.log '[synth] ' + msg
|
21
24
|
|
22
25
|
##
|
23
|
-
# Events
|
26
|
+
# Synth Events
|
24
27
|
|
25
28
|
$(document).on 'synth:subscribe', ->
|
26
29
|
Synth.subscribe()
|
@@ -37,13 +40,7 @@ $ ->
|
|
37
40
|
Synth.log 'Connected'
|
38
41
|
|
39
42
|
Synth.connection.onmessage = (msg) ->
|
40
|
-
|
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(' ')
|
43
|
+
Synth.update(msg)
|
47
44
|
|
48
45
|
Synth.connection.onclose = ->
|
49
46
|
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.4
|
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-05-
|
13
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redis
|
17
|
-
requirement: &
|
17
|
+
requirement: &70155297025200 !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: *70155297025200
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: redis-namespace
|
28
|
-
requirement: &
|
28
|
+
requirement: &70155297024520 !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: *70155297024520
|
37
37
|
description: Real-time for Rails
|
38
38
|
email:
|
39
39
|
- synth@stackd.com
|