ddp-server 0.0.2 → 0.0.3

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: ec53e4163f85296c7c2dd0201e980a920d4467af
4
- data.tar.gz: 3bf64d5e0e8081498875d86c82e5475f29dc373e
3
+ metadata.gz: 5321d037bf5da044192560738c9bad091acde4b7
4
+ data.tar.gz: a2898c62564467a37ef8f4bc090c981d00c67fbd
5
5
  SHA512:
6
- metadata.gz: f03405546f2eda99a66ee4a1bf507ffa202f3fa957f2cd81ad99946b1b15d94d8eb3af43d89d069f397584af1d626219a3a0652e53d3e0659b4df18b4f466c75
7
- data.tar.gz: 9b2f36255c527a46bdb170b8929c9b8b1392f06f0e0c18af203b75ed6b866e3f85fabc6cff6cf472a5861a93fec5ce411d8e8cdebf6c25620df66e918fb90c69
6
+ metadata.gz: 953c4d98aee48c9708223c2b9664dfe0ada3e5e2a85a02dac5d25620cafd67a7029908c1fa82eaf4b21a7b06cb6e39306b5f83fa3e10346fc7558ac88b1e4580
7
+ data.tar.gz: ca9e0fb1e9f42f73291c3dab6d9b968f25daae2b6094a18cc39272b756f1aae1c837dd6b27c9b53a1f62e5dfe245f7e21ef58926d47e3796a6cbdb6f48b2f723
@@ -6,58 +6,58 @@ module DDP
6
6
  def handle_data
7
7
  case @message['msg']
8
8
  when 'sub'
9
- handle_sub
9
+ handle_sub(@message['id'], @message['name'], @message['params'])
10
10
  true
11
11
  when 'unsub'
12
- handle_unsub
12
+ handle_unsub(@message['id'])
13
13
  true
14
14
  else
15
15
  false
16
16
  end
17
17
  end
18
18
 
19
- def handle_sub
19
+ def handle_sub(_id, _name, _params)
20
20
  raise 'Must be overridden'
21
21
  end
22
22
 
23
- def handle_unsub
23
+ def handle_unsub(_id)
24
24
  raise 'Must be overridden'
25
25
  end
26
26
 
27
- def nosub(id, error = nil)
27
+ def send_nosub(id, error = nil)
28
28
  message = { msg: 'nosub', id: id }
29
29
  message.merge!(error: error) if error
30
30
  write_message message
31
31
  end
32
32
 
33
- def added(collection, id, fields = nil)
33
+ def send_added(collection, id, fields = nil)
34
34
  message = { msg: 'added', id: id, collection: collection }
35
35
  message.merge!(fields: fields) if fields
36
36
  write_message message
37
37
  end
38
38
 
39
- def changed(collection, id, fields = nil, cleared = nil)
39
+ def send_changed(collection, id, fields = nil, cleared = nil)
40
40
  message = { msg: 'changed', id: id, collection: collection }
41
41
  message.merge!(fields: fields) if fields
42
42
  message.merge!(cleared: cleared) if cleared
43
43
  write_message message
44
44
  end
45
45
 
46
- def removed(collection, id)
46
+ def send_removed(collection, id)
47
47
  write_message msg: 'removed', collection: collection, id: id
48
48
  end
49
49
 
50
- def ready(subs)
50
+ def send_ready(subs)
51
51
  write_message msg: 'ready', subs: subs
52
52
  end
53
53
 
54
- def added_before(collection, id, fields = nil, before = nil)
54
+ def send_added_before(collection, id, fields = nil, before = nil)
55
55
  message = { msg: 'addedBefore', id: id, collection: collection, before: before }
56
56
  message.merge!(fields: fields) if fields
57
57
  write_message message
58
58
  end
59
59
 
60
- def moved_before(collection, id, before = nil)
60
+ def send_moved_before(collection, id, before = nil)
61
61
  write_message msg: 'movedBefore', id: id, collection: collection, before: before
62
62
  end
63
63
  end
@@ -3,33 +3,39 @@ module DDP
3
3
  module Protocol
4
4
  # Protocol regarding remote procedure calls
5
5
  module RPC
6
+ NO_RESULT = Object.new
7
+
6
8
  def handle_rpc
7
9
  case @message['msg']
8
10
  when 'method'
9
- handle_method
11
+ handle_method(@message['id'], @message['method'], @message['params'])
10
12
  true
11
13
  else
12
14
  false
13
15
  end
14
16
  end
15
17
 
16
- def handle_method
18
+ def handle_method(_id, _method, _params)
17
19
  raise 'Must be overridden'
18
20
  end
19
21
 
20
- def result(id, result = nil)
22
+ def send_result(id, result = NO_RESULT)
21
23
  message = { msg: 'result', id: id }
22
- if result
23
- if result['error']
24
- message['error'] = result
25
- else
26
- message['result'] = result
27
- end
28
- end
24
+ message['result'] = result unless result == NO_RESULT
25
+ write_message(message)
26
+ end
27
+
28
+ def send_error_result(id, error)
29
+ message = { msg: 'result', id: id }
30
+ message['error'] = {
31
+ error: error.class.name,
32
+ reason: error.message,
33
+ details: "Backtrace: \n#{error.backtrace.join("\n")}"
34
+ }
29
35
  write_message(message)
30
36
  end
31
37
 
32
- def updated(methods)
38
+ def send_updated(methods)
33
39
  write_message msg: 'updated', methods: methods
34
40
  end
35
41
  end
@@ -1,6 +1,6 @@
1
1
  module DDP
2
2
  # We use semantic versioning
3
3
  module Server
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddp-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-18 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler