synth 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Synth
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,11 +3,17 @@
3
3
 
4
4
  class Synth
5
5
 
6
- @establishConnection = ->
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.establishConnection()
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
- Synth.log 'Message received: ' + msg.data
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.2
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-04-21 00:00:00.000000000 Z
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: &70349182991980 !ruby/object:Gem::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: *70349182991980
25
+ version_requirements: *70300189145360
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: redis-namespace
28
- requirement: &70349182986760 !ruby/object:Gem::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: *70349182986760
36
+ version_requirements: *70300189144920
37
37
  description: Real-time for Rails
38
38
  email:
39
39
  - synth@stackd.com