backrub 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -0
- data/Rakefile +12 -0
- data/backrub.gemspec +2 -0
- data/lib/backrub.rb +12 -5
- data/test/backrub_test.rb +52 -0
- data/test/test_helper.rb +5 -0
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27968ba3418abbcab97c0b582bcfab4c70a18178
|
4
|
+
data.tar.gz: b38040b3676d3c4a765e7cf4ce8711a6c50e5aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fe540cc437d3766e524506ed6dc60499a376b6a478e0a349ecf676c1ffa9c1e991a969ae7a32681540c6e7fd48b6dc8a8f90b85de7d9f3982f1a188d5d77ace
|
7
|
+
data.tar.gz: 75cc23037ab89e3bfc1d9fe9f503008a3ce510da7c5527ff6fdb92bdb68cfbd92a6109aaa6dfe9326363a027881f2aa8919502e1e99249a97b92cef518b40f0a
|
data/Gemfile.lock
CHANGED
@@ -7,6 +7,10 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
metaclass (0.0.2)
|
11
|
+
minitest (4.7.5)
|
12
|
+
mocha (1.0.0)
|
13
|
+
metaclass (~> 0.0.1)
|
10
14
|
rake (10.1.1)
|
11
15
|
redis (3.0.7)
|
12
16
|
|
@@ -16,4 +20,6 @@ PLATFORMS
|
|
16
20
|
DEPENDENCIES
|
17
21
|
backrub!
|
18
22
|
bundler (~> 1.5)
|
23
|
+
minitest
|
24
|
+
mocha
|
19
25
|
rake
|
data/Rakefile
CHANGED
data/backrub.gemspec
CHANGED
data/lib/backrub.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'redis'
|
2
2
|
|
3
3
|
module Backrub
|
4
|
-
VERSION = "0.0
|
4
|
+
VERSION = "1.0.0"
|
5
5
|
|
6
6
|
DEFAULT_BACKLOG_SIZE = 100
|
7
7
|
|
@@ -21,12 +21,19 @@ module Backrub
|
|
21
21
|
raise ArgumentError.new "You have to pass at least one channel" if channels.count.zero?
|
22
22
|
|
23
23
|
if channels.count == 1 && channels.first.is_a?(Hash)
|
24
|
-
channels.first
|
25
|
-
|
26
|
-
|
24
|
+
hash = channels.first
|
25
|
+
|
26
|
+
hash.each do |channel, offset|
|
27
|
+
if offset > 0
|
28
|
+
backlog = redis.lrange(channel, 0, offset - 1)
|
29
|
+
|
30
|
+
backlog.reverse_each do |message|
|
31
|
+
yield channel.to_s, message
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
|
-
|
35
|
+
|
36
|
+
channels = hash.keys
|
30
37
|
end
|
31
38
|
|
32
39
|
begin
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BackrubTest < MiniTest::Unit::TestCase
|
4
|
+
def test_publishing_messages
|
5
|
+
channel = "test"
|
6
|
+
message = "data"
|
7
|
+
Backrub.redis.expects(:publish).with(channel, message)
|
8
|
+
Backrub.redis.expects(:lpush).with(channel, message)
|
9
|
+
Backrub.redis.expects(:ltrim).with(channel, 0, Backrub::DEFAULT_BACKLOG_SIZE - 1)
|
10
|
+
|
11
|
+
Backrub.publish(channel, message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_subscribing
|
15
|
+
fake_redis = mock()
|
16
|
+
subscribe_object = mock()
|
17
|
+
subscribe_object.expects(:message).yields(["test", "data"])
|
18
|
+
fake_redis.expects(:subscribe).with("test").yields(subscribe_object)
|
19
|
+
fake_redis.expects(:quit)
|
20
|
+
|
21
|
+
Backrub.expects(:new_redis).returns(fake_redis)
|
22
|
+
|
23
|
+
Backrub.subscribe("test") do |channel, message|
|
24
|
+
assert_equal "test", channel
|
25
|
+
assert_equal "data", message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_subscribing_with_hash_backlog
|
30
|
+
channels = {
|
31
|
+
first_channel: 0,
|
32
|
+
second_channel: 2
|
33
|
+
}
|
34
|
+
second_channel_data = ["first_bit", "second_bit"]
|
35
|
+
Backrub.redis.expects(:lrange).with(:second_channel, 0, 1).returns(second_channel_data.dup)
|
36
|
+
second_channel_data.unshift("third_bit")
|
37
|
+
|
38
|
+
fake_redis = mock()
|
39
|
+
subscribe_object = mock()
|
40
|
+
subscribe_object.expects(:message).yields(["second_channel", "third_bit"])
|
41
|
+
|
42
|
+
fake_redis.expects(:subscribe).with(:first_channel, :second_channel).yields(subscribe_object)
|
43
|
+
fake_redis.expects(:quit)
|
44
|
+
|
45
|
+
Backrub.expects(:new_redis).returns(fake_redis)
|
46
|
+
|
47
|
+
Backrub.subscribe(channels) do |channel, message|
|
48
|
+
assert_equal "second_channel", channel
|
49
|
+
assert_equal second_channel_data.pop, message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backrub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bouke van der Bijl
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Redis-based pubsub system with a backlog
|
56
84
|
email:
|
57
85
|
- boukevanderbijl@gmail.com
|
@@ -67,6 +95,8 @@ files:
|
|
67
95
|
- Rakefile
|
68
96
|
- backrub.gemspec
|
69
97
|
- lib/backrub.rb
|
98
|
+
- test/backrub_test.rb
|
99
|
+
- test/test_helper.rb
|
70
100
|
homepage: ''
|
71
101
|
licenses:
|
72
102
|
- MIT
|
@@ -91,5 +121,7 @@ rubygems_version: 2.2.0
|
|
91
121
|
signing_key:
|
92
122
|
specification_version: 4
|
93
123
|
summary: Redis-based pubsub system with a backlog
|
94
|
-
test_files:
|
124
|
+
test_files:
|
125
|
+
- test/backrub_test.rb
|
126
|
+
- test/test_helper.rb
|
95
127
|
has_rdoc:
|