wampus 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64e79cb9e7b99c33ed789828ebe831a943f1613e
4
- data.tar.gz: ebaae0ad6da9e25be70144855b23e3a5d352125c
3
+ metadata.gz: 24dd3f5e9601271d25b1ba20bb489dcdc9d9282c
4
+ data.tar.gz: 8af28ecdb9b6db135c99082f74b40e918be2e5c7
5
5
  SHA512:
6
- metadata.gz: 071a2bd09533edf1719c350245781206639fa919319e6306fa3d69eccebd5b7252e128805b2fff0c7d9f7fe6bb359a78c8afca03b78dcecc91c5e29a0e331c62
7
- data.tar.gz: 1b84d5f9be5b1606dbc863efc2b0c1babfc47326e650edccc8f7c0b877826c873066a26bd5cc25d75126f15afdcfe4aa944d3398e0d2b812375e2ec9718c1af0
6
+ metadata.gz: e475438bf58140e41989c659525af5af26a3b0305aafec3cd5af6cc10068eb179a374a847c0768dc3b5b59d9832511c18fd1822187768dfe3f4a7092de52cdfe
7
+ data.tar.gz: 033812f181b04eb2dfd3295fd68f98917965be1b5718bceb4ad058fdaefc6d16316747f2bbf174f5dacf391b156f9fcf3bb324e09963a6bbe2c8e2454893345e
@@ -6,45 +6,47 @@ module Wampus
6
6
  module Redis
7
7
  extend ActiveSupport::Concern
8
8
 
9
+ attr_reader :redis_config
10
+
11
+ def initialize(*args)
12
+ @redis_config = redis_defaults.dup
13
+ super(*args) if defined? super
14
+ end
15
+
9
16
  included do
10
- class_attribute :backend_redis_defaults
11
- self.backend_defaults = {
12
- :redis => {
13
- :host => 'localhost',
14
- :port => 6379,
15
- :database => 0,
16
- :password => nil,
17
- :gc => 60,
18
- :lock_timeout => 120,
19
- :namespace => ''
20
- }
17
+ class_attribute :redis_defaults
18
+ self.redis_defaults = {
19
+ :host => 'localhost',
20
+ :port => 6379,
21
+ :database => 0,
22
+ :password => nil,
23
+ :gc => 60,
24
+ :lock_timeout => 120,
25
+ :namespace => ''
21
26
  }
22
- class_attribute :backend_redis_config
23
- self.backend_config = {:redis => {}}
24
27
  end
25
28
 
26
29
  module ClassMethods
27
- def configure_backend(backend, options = {})
28
- backend_config[backend] = backend_defaults[backend].merge options
29
-
30
+ def configure_redis(options = {})
31
+ redis_config = redis_defaults.merge options
30
32
  end
31
33
  end
32
34
 
33
- def connect_backend
34
- @events_namespace = backend_config[:redis][:namespace] + ':events'
35
+ def connect_to_redis
36
+ @events_namespace = redis_config[:namespace] + ':events'
35
37
 
36
38
  @completed_events = []
37
39
 
38
- @redis = ::Redis.new(:host => backend_config[:redis][:host], :port => backend_config[:redis][:port])
39
- @subscriber = ::Redis.new(:host => backend_config[:redis][:host], :port => backend_config[:redis][:port])
40
+ @redis = ::Redis.new(:host => redis_config[:host], :port => redis_config[:port])
41
+ @subscriber = ::Redis.new(:host => redis_config[:host], :port => redis_config[:port])
40
42
 
41
- if backend_config[:redis][:password]
42
- @redis.auth(backend_config[:redis][:password])
43
- @subscriber.auth(backend_config[:redis][:password])
43
+ if redis_config[:password]
44
+ @redis.auth(redis_config[:password])
45
+ @subscriber.auth(redis_config[:password])
44
46
  end
45
47
 
46
- @redis.select(backend_config[:redis][:database])
47
- @subscriber.select(backend_config[:redis][:database])
48
+ @redis.select(redis_config[:database])
49
+ @subscriber.select(redis_config[:database])
48
50
 
49
51
  Thread.new do
50
52
  @subscriber.subscribe(@events_namespace) do |on|
@@ -56,45 +58,45 @@ module Wampus
56
58
 
57
59
  end
58
60
 
59
- def create_event(connection, topic, payload, excluded, included)
60
- create_event_on_redis(connection.id, topic.uri, payload, excluded, included)
61
- end
61
+ def create_event(connection, topic, payload, excluded, included)
62
+ create_event_on_redis(connection.id, topic.uri, payload, excluded, included)
63
+ end
62
64
 
63
- private
65
+ private
64
66
 
65
- def create_event_on_redis(connection_id, topic_uri, payload, excluded, included)
66
- @redis.publish @events_namespace, [SecureRandom.uuid, connection_id, topic_uri, payload, excluded, included].to_json
67
- end
67
+ def create_event_on_redis(connection_id, topic_uri, payload, excluded, included)
68
+ @redis.publish @events_namespace, [SecureRandom.uuid, connection_id, topic_uri, payload, excluded, included].to_json
69
+ end
68
70
 
69
- def subscribe_to_events
70
- Thread.new do
71
- @subscriber.subscribe(@events_ns) do |on|
72
- on.message do |channel, message|
73
- handle_message_from_redis(message)
74
- end
71
+ def subscribe_to_events
72
+ Thread.new do
73
+ @subscriber.subscribe(@events_ns) do |on|
74
+ on.message do |channel, message|
75
+ handle_message_from_redis(message)
75
76
  end
76
77
  end
77
78
  end
79
+ end
78
80
 
79
- def handle_message_from_redis(message)
80
- begin
81
- id, connection_id, uri, payload, excluded, included = JSON.parse(message)
81
+ def handle_message_from_redis(message)
82
+ begin
83
+ id, connection_id, uri, payload, excluded, included = JSON.parse(message)
82
84
 
83
- connection = find_connections(:id => connection_id).first
84
- topic = topic_for_uri uri
85
+ connection = find_connections(:id => connection_id).first
86
+ topic = topic_for_uri uri
85
87
 
86
- return unless topic
88
+ return unless topic
87
89
 
88
- topic.subscribers(connection, excluded, included) do |subscribers|
89
- subscribers.each do |connection|
90
- connection.write event_msg(topic.uri, payload)
91
- end
90
+ topic.subscribers(connection, excluded, included) do |subscribers|
91
+ subscribers.each do |connection|
92
+ connection.write event_msg(topic.uri, payload)
92
93
  end
93
- rescue => error
94
- # TODO Handle Error
95
94
  end
95
+ rescue => error
96
+ # TODO Handle Error
96
97
  end
97
-
98
98
  end
99
+
99
100
  end
100
- end
101
+ end
102
+ end
@@ -1,3 +1,3 @@
1
1
  module Wampus
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wampus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Stack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler