ddp-server-rethinkdb 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ddp-server-rethinkdb.gemspec +1 -2
- data/examples/messages.rb +1 -1
- data/lib/ddp/server/rethinkdb/api.rb +18 -1
- data/lib/ddp/server/rethinkdb/version.rb +1 -1
- data/lib/ddp/server/rethinkdb.rb +0 -2
- metadata +4 -20
- data/lib/ddp/server/rethinkdb/subscription.rb +0 -30
- data/lib/ddp/server/rethinkdb/websocket.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc02ef7ca06554ea7ef61095ca1f68b2216bbcfa
|
4
|
+
data.tar.gz: d639840e48515eb7b9a22dfe11098503c8b4c28e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b8917caf19f51fdfb2fce59a5d8083732c3208fccd98280328f3b4ff61622ebff32e911540b6e09170ffc229c10be67ad43bd8b792dd106fc1705701d4bfdc9
|
7
|
+
data.tar.gz: cc39c1677ef4ef5818ee930c476c8be648b9c96b8b7fcabfe7185ce956537889c30b822cb7d299388bad47ea739e48bcc35724f5c371af521aeef78466ae90b9
|
@@ -21,8 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
|
24
|
-
spec.add_dependency 'ddp-server', '>= 0.
|
25
|
-
spec.add_dependency 'celluloid-websocket', '>= 0.0.9'
|
24
|
+
spec.add_dependency 'ddp-server', '>= 0.1.1'
|
26
25
|
spec.add_dependency 'rethinkdb'
|
27
26
|
spec.add_dependency 'connection_pool'
|
28
27
|
end
|
data/examples/messages.rb
CHANGED
@@ -23,7 +23,7 @@ module DDP
|
|
23
23
|
|
24
24
|
def collection_query(name, *params)
|
25
25
|
raise 'No such collection' unless @collections.include? name
|
26
|
-
send(name, *params)
|
26
|
+
wrap_query send(name, *params)
|
27
27
|
end
|
28
28
|
|
29
29
|
def database
|
@@ -69,6 +69,23 @@ module DDP
|
|
69
69
|
@collections = collections_module.instance_methods.map(&:to_s)
|
70
70
|
singleton_class.include collections_module
|
71
71
|
end
|
72
|
+
|
73
|
+
def wrap_query(query)
|
74
|
+
lambda do |&on_update|
|
75
|
+
connection = new_connection
|
76
|
+
results = query.run(connection)
|
77
|
+
results.each { |r| on_update.call(nil, r) }
|
78
|
+
wrap_changes(query, connection, on_update)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def wrap_changes(query, conn, on_update)
|
83
|
+
query.changes().run(conn).each do |change|
|
84
|
+
old_value = change['old_val']
|
85
|
+
new_value = change['new_val']
|
86
|
+
on_update.call(old_value, new_value)
|
87
|
+
end
|
88
|
+
end
|
72
89
|
end
|
73
90
|
end
|
74
91
|
end
|
data/lib/ddp/server/rethinkdb.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddp-server-rethinkdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tinco Andringa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,28 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.1.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: celluloid-websocket
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.0.9
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.0.9
|
54
|
+
version: 0.1.1
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rethinkdb
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,9 +98,7 @@ files:
|
|
112
98
|
- examples/messages.rb
|
113
99
|
- lib/ddp/server/rethinkdb.rb
|
114
100
|
- lib/ddp/server/rethinkdb/api.rb
|
115
|
-
- lib/ddp/server/rethinkdb/subscription.rb
|
116
101
|
- lib/ddp/server/rethinkdb/version.rb
|
117
|
-
- lib/ddp/server/rethinkdb/websocket.rb
|
118
102
|
homepage: https://github.com/d-snp/ruby-ddp-server-rethinkdb
|
119
103
|
licenses:
|
120
104
|
- MIT
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module DDP
|
2
|
-
module Server
|
3
|
-
module RethinkDB
|
4
|
-
# Actor that asynchronously monitors a collection
|
5
|
-
class Subscription
|
6
|
-
include Celluloid
|
7
|
-
|
8
|
-
attr_reader :name, :stopped
|
9
|
-
alias_method :stopped?, :stopped
|
10
|
-
|
11
|
-
def initialize(listener, id, name, query)
|
12
|
-
@stopped = false
|
13
|
-
@name = name
|
14
|
-
async.read_loop(listener, query, id)
|
15
|
-
end
|
16
|
-
|
17
|
-
def read_loop(listener, query, id)
|
18
|
-
query.changes.run(listener.api.new_connection).each do |change|
|
19
|
-
listener.subscription_update(id, change)
|
20
|
-
break if stopped?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def stop
|
25
|
-
@stopped = true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module DDP
|
2
|
-
module Server
|
3
|
-
module RethinkDB
|
4
|
-
# Implementation of the WebSocket DDP::Server
|
5
|
-
class WebSocket < DDP::Server::WebSocket
|
6
|
-
attr_reader :api
|
7
|
-
|
8
|
-
def self.rack(api, config, pool_config = {})
|
9
|
-
super(pool_config.merge(args: [api, config]))
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(api_class, config)
|
13
|
-
@api = api_class.new(config)
|
14
|
-
@subscriptions = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
def handle_sub(id, name, params)
|
18
|
-
params ||= []
|
19
|
-
query = @api.collection_query(name, *params)
|
20
|
-
|
21
|
-
# TODO: this should somehow be atomically executed so we dont have overlap.
|
22
|
-
@subscriptions[id] = Subscription.new(self, id, name, query)
|
23
|
-
|
24
|
-
@api.with_connection do |conn|
|
25
|
-
query.run(conn).each { |r| send_added(name, r['id'], r) }
|
26
|
-
end
|
27
|
-
|
28
|
-
send_ready([id])
|
29
|
-
rescue => e
|
30
|
-
send_error_result(id, e)
|
31
|
-
end
|
32
|
-
|
33
|
-
def subscription_update(id, change)
|
34
|
-
subscription_name = @subscriptions[id].name
|
35
|
-
old_value = change['old_val']
|
36
|
-
new_value = change['new_val']
|
37
|
-
|
38
|
-
return send_added(subscription_name, new_value['id'], new_value) if old_value.nil?
|
39
|
-
return send_removed(subscription_name, old_value['id']) if new_value.nil?
|
40
|
-
|
41
|
-
cleared = old_value.keys.reject { |key| new_value.include? key }
|
42
|
-
send_changed(subscription.name, old_value['id'], new_value, cleared)
|
43
|
-
end
|
44
|
-
|
45
|
-
def handle_unsub(id)
|
46
|
-
subscription = @subscriptions.delete(id)
|
47
|
-
subscription.stop unless subscription.nil?
|
48
|
-
send_nosub(id)
|
49
|
-
end
|
50
|
-
|
51
|
-
def handle_method(id, method, params)
|
52
|
-
params ||= []
|
53
|
-
result = @api.invoke_rpc(method, *params)
|
54
|
-
send_result(id, result)
|
55
|
-
rescue => e
|
56
|
-
send_error_result(id, e)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|