rcom 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: 57eeb76581f7c4b2e8a370e59c286e47d4a3eeb8
4
- data.tar.gz: d417c03fd9471cf183dcbb2216a62ac9d356bbb6
3
+ metadata.gz: a4a59231e2507f9f5010d142bfeb28efeba2e8e6
4
+ data.tar.gz: a141a111f2e29d337ddcad3a60626885e88430bb
5
5
  SHA512:
6
- metadata.gz: 5be8b6c88113107329e7a061e04ffbd1785111f57c112df4c6edf5ae0833968595678812a0ff79f9e9688b8827eb08087a603c5055dcb2b517e460d809c649c0
7
- data.tar.gz: 8bc4c1f4c67821cf3ea3190e6a8b9eb0430f7c09993e27bc13882363be3147a3263b5e0abc4b95e4e689378af3580c81993fa8989e9d0e85a4a52f8db61c5370
6
+ metadata.gz: b7c512e707d70fb3520bcfab86146053b14949d9d28fb3ed3a73268d1ed5df04c337f7a4766d38d5d4b7480d7e68535ac31870868fd5bc42dff2548fc5288d28
7
+ data.tar.gz: cf8fe056685e4024d07f5e0829c9f5c911303e75ce5b1f7254796c3a755660041fd4971a60ea353e6c3a7c5b865a0e566d15e0fedeb70831133c091323927ed3
data/README.md CHANGED
@@ -24,9 +24,12 @@ Rcom supports the request-response, publish-subscribe and task queues patterns f
24
24
 
25
25
  A node represents a Redis connection to a server address specified with an ENV variable.
26
26
 
27
+ ```sh
28
+ #.env
29
+ LOCAL=redis://localhost
30
+ ```
31
+
27
32
  ```ruby
28
- # Specify this in your .env file.
29
- ENV['local'] = 'redis://localhost'
30
33
  node = Rcom::Node.new('local').connect
31
34
  ```
32
35
 
data/lib/rcom/node.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  module Rcom
2
+ # A node represents a Redis server and has an uri.
2
3
  class Node
4
+ # @return [String]
3
5
  attr_reader :uri
4
6
 
7
+ # @param uri [String] Example: 'local'
8
+ # @raise [ArgumentError] uri is not in .env.
5
9
  def initialize(uri)
6
10
  raise ArgumentError unless ENV[uri.upcase]
7
11
  @uri = ENV[uri.upcase]
8
12
  end
9
13
 
14
+ # Connects to Redis.
15
+ # @return [Redis]
10
16
  def connect
11
17
  Redis.new(url: uri)
12
18
  end
data/lib/rcom/rpc.rb CHANGED
@@ -1,12 +1,24 @@
1
1
  module Rcom
2
+ # Rpc implements the request/response pattern.
2
3
  class Rpc
3
- attr_reader :node, :service
4
+ # @return [Rcom::Node]
5
+ attr_reader :node
6
+ # @return [String]
7
+ attr_reader :service
4
8
 
9
+ # @param params [Hash]
10
+ # @option params :node [Rcom::Node] Example: Rcom::Node.new('local').connect
11
+ # @option params :service [String] Example: 'auth'
5
12
  def initialize(params)
6
13
  @node = params[:node]
7
14
  @service = params[:service]
8
15
  end
9
16
 
17
+ # @param params [Hash]
18
+ # @option params :route [String] Example: 'users.key'
19
+ # @option params :args Example: 1
20
+ # @return [reply, nil] Returns the reply or nil if the
21
+ # request can't be processed.
10
22
  def request(params)
11
23
  begin
12
24
  request = {
@@ -27,6 +39,8 @@ module Rcom
27
39
  end
28
40
  end
29
41
 
42
+ # Subscribe to the service and listen to requests.
43
+ # @yieldparam router [Rcom::Router] A router to match the request.
30
44
  def subscribe
31
45
  begin
32
46
  loop do
@@ -47,13 +61,16 @@ module Rcom
47
61
  end
48
62
  end
49
63
 
64
+ # A router can match on a particular route.
50
65
  class Router
51
66
  attr_accessor :message, :reply
52
67
 
68
+ # @param message [Hash] The message received with the request.
53
69
  def initialize(message)
54
70
  @message = message
55
71
  end
56
72
 
73
+ # @yieldparam args
57
74
  def on(route)
58
75
  return nil unless message[:route] == route
59
76
  yield message[:args]
data/lib/rcom/task.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  module Rcom
2
+ # Implements tasks and queues.
2
3
  class Task
3
4
  attr_reader :node, :queue
4
5
 
5
- def initialize(args)
6
- @node = args[:node]
7
- @queue = args[:queue]
6
+ # @param params [Hash]
7
+ # @option params :node [Rcom::Node]
8
+ # @option params :queue [String] Example: 'messages'
9
+ def initialize(params)
10
+ @node = params[:node]
11
+ @queue = params[:queue]
8
12
  end
9
13
 
14
+ # @param message [Hash]
15
+ # @return [true, nil] True if the message can be queued, otherwise nil.
10
16
  def publish(message)
11
17
  begin
12
18
  node.lpush(queue, message.to_msgpack)
@@ -16,6 +22,7 @@ module Rcom
16
22
  end
17
23
  end
18
24
 
25
+ # @yieldparam message [Hash] the message received.
19
26
  def subscribe
20
27
  begin
21
28
  loop do
data/lib/rcom/topic.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  module Rcom
2
+ # Implements pub/sub over topics.
2
3
  class Topic
3
4
  attr_reader :node, :key
4
5
 
5
- def initialize(args)
6
- @node = args[:node]
7
- @key = args[:key]
6
+ # @param params [Hash]
7
+ # @option params :node [Rcom::Node]
8
+ # @option params :key [String] Example: 'services'
9
+ def initialize(params)
10
+ @node = params[:node]
11
+ @key = params[:key]
8
12
  end
9
13
 
14
+ # @param message [Hash]
15
+ # @return [true, nil] true if it can be published, otherwise nil.
10
16
  def publish(message)
11
17
  begin
12
18
  node.publish(key, message.to_msgpack)
@@ -16,6 +22,7 @@ module Rcom
16
22
  end
17
23
  end
18
24
 
25
+ # @yieldparam message [Hash] the message received.
19
26
  def subscribe
20
27
  begin
21
28
  node.subscribe(key) do |on|
data/lib/rcom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rcom
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['local'] = 'redis://localhost'
2
+ ENV['LOCAL'] = 'redis://localhost'
3
3
 
4
4
  require 'rcom'
5
5
 
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['local'] = 'redis://localhost'
2
+ ENV['LOCAL'] = 'redis://localhost'
3
3
 
4
4
  require 'rcom'
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcom
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
  - Marco Lisci