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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa94a4cca936bfbf2bf20c120067c298b8d17e6d
4
- data.tar.gz: 56313a5652b9ff977015507ed2b42e8ac064f481
3
+ metadata.gz: fc02ef7ca06554ea7ef61095ca1f68b2216bbcfa
4
+ data.tar.gz: d639840e48515eb7b9a22dfe11098503c8b4c28e
5
5
  SHA512:
6
- metadata.gz: 00b8772d4df7bc4f20d200c1a5e12c30de75a29b2fb9410164f6f0e65fe85b6d16663bbf9134f512fe3d280b181a5f80dc61e23a01d0bddd3931fde2635a532f
7
- data.tar.gz: c4d2e8d3d75b7b4e2645786f16b9cf7c41307047918fd79d02eb6b95e077d7906ef5a8e4d2cd918853a237850400c953e050687d6d4405f1b3897166854cd83c
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.0.4'
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
@@ -32,4 +32,4 @@ config = {
32
32
  database: 'message'
33
33
  }
34
34
 
35
- run DDP::Server::RethinkDB::WebSocket.rack(Messager, config)
35
+ run DDP::Server::WebSocket.rack(Messager, config)
@@ -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
@@ -2,7 +2,7 @@ module DDP
2
2
  module Server
3
3
  # Include the version
4
4
  module RethinkDB
5
- VERSION = '0.0.4'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  end
8
8
  end
@@ -4,8 +4,6 @@ require 'celluloid'
4
4
  require 'ddp/server'
5
5
  require 'ddp/server/rethinkdb'
6
6
  require 'ddp/server/rethinkdb/api'
7
- require 'ddp/server/rethinkdb/subscription'
8
- require 'ddp/server/rethinkdb/websocket'
9
7
 
10
8
  module DDP
11
9
  module Server
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
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-01 00:00:00.000000000 Z
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.0.4
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.0.4
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