ddp-server-rethinkdb 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -6
- data/examples/messages.rb +12 -8
- data/lib/ddp/server/rethinkdb/version.rb +1 -1
- data/lib/ddp/server/rethinkdb.rb +6 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3762c90b25c888a4b99e65b397456dae694fd44a
|
4
|
+
data.tar.gz: 0c0d33f7dfcf26ba39c4d9e52a681647a304bb29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50f516ea1223ac1f42a469920af571f8681e667966ab656ea4c56f1cbd97968d0fde6ec6a7b207cc1b9f0fca3d0ccb4b8d83ca218a877a286c9bbc1d3bc7d948
|
7
|
+
data.tar.gz: 812f96b5d42529d100a5629c1f3e570aabdc18f7bd84b8faeb183dac40adc079447b25a65bd19dac1de2336d5f9e0dbd731d70bce2e16fe484ce4b943f71061a
|
data/README.md
CHANGED
@@ -16,14 +16,16 @@ class Messager < DDP::Server::RethinkDB::API
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
module RPC
|
20
|
+
def send_message(message)
|
21
|
+
with_connection do |conn|
|
22
|
+
table('messages').insert(from: name, message: message).run(conn)
|
23
|
+
end
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
|
25
|
-
table('messages').insert(from: name, message: message).run(conn)
|
26
|
-
end
|
27
|
+
def name
|
28
|
+
@name ||= "Guest#{rand(10..100)}"
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -36,6 +38,7 @@ config = {
|
|
36
38
|
}
|
37
39
|
|
38
40
|
run DDP::Server::RethinkDB::WebSocket.rack(Messager, config)
|
41
|
+
|
39
42
|
```
|
40
43
|
|
41
44
|
## Installation
|
data/examples/messages.rb
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
require 'ddp/server/rethinkdb'
|
2
2
|
|
3
|
+
# A simple messaging API
|
3
4
|
class Messager < DDP::Server::RethinkDB::API
|
4
|
-
|
5
|
-
|
5
|
+
# Define a module named Collections that exposes subscribable rethinkdb queries
|
6
6
|
module Collections
|
7
7
|
def messages
|
8
8
|
table('messages')
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# Define a module named RPC that exposes RPC methods
|
13
|
+
module RPC
|
14
|
+
def send_message(message)
|
15
|
+
with_connection do |conn|
|
16
|
+
table('messages').insert(from: name, message: message).run(conn)
|
17
|
+
end
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
21
|
+
# Other methods are not available to RPC nor are they subscribable
|
22
|
+
def name
|
23
|
+
@name ||= "Guest#{rand(10..100)}"
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
data/lib/ddp/server/rethinkdb.rb
CHANGED
@@ -13,15 +13,18 @@ module DDP
|
|
13
13
|
|
14
14
|
attr_reader :api
|
15
15
|
|
16
|
-
def self.rack(api, config, pool_config={})
|
16
|
+
def self.rack(api, config, pool_config = {})
|
17
17
|
super(pool_config.merge(args: [api, config]))
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize(api_class, config)
|
21
21
|
collections_module = api_class.const_get :Collections
|
22
|
+
rpc_module = api_class.const_get :RPC
|
22
23
|
@collections = collections_module.instance_methods.map(&:to_s)
|
24
|
+
@rpc_methods = rpc_module.instance_methods.map(&:to_s)
|
23
25
|
@api = api_class.new(config)
|
24
26
|
@api.singleton_class.include collections_module
|
27
|
+
@api.singleton_class.include rpc_module
|
25
28
|
@subscriptions = {}
|
26
29
|
end
|
27
30
|
|
@@ -52,6 +55,7 @@ module DDP
|
|
52
55
|
|
53
56
|
def handle_method(id, method, params)
|
54
57
|
params ||= []
|
58
|
+
raise 'No such method' unless @rpc_methods.include? method
|
55
59
|
result = @api.send(method, *params)
|
56
60
|
send_result(id, result)
|
57
61
|
rescue => e
|
@@ -96,6 +100,7 @@ module DDP
|
|
96
100
|
include Celluloid::Logger
|
97
101
|
|
98
102
|
attr_reader :name, :stopped
|
103
|
+
alias_method :stopped?, :stopped
|
99
104
|
|
100
105
|
def initialize(listener, id, name, query)
|
101
106
|
@stopped = false
|
@@ -115,10 +120,6 @@ module DDP
|
|
115
120
|
def stop
|
116
121
|
@stopped = true
|
117
122
|
end
|
118
|
-
|
119
|
-
def stopped?
|
120
|
-
@stopped
|
121
|
-
end
|
122
123
|
end
|
123
124
|
end
|
124
125
|
end
|
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.0.2
|
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-02-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|