msngr 0.0.1 → 0.1.0

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
- SHA1:
3
- metadata.gz: 80f389f5be19c06e918bbabc6758063ebc871298
4
- data.tar.gz: d152dc1d6e25696fa09fc917248dfbb599483c1e
2
+ SHA256:
3
+ metadata.gz: 3dda6c846ac32026c44325fb64c9d06d74b07972944a54dd19bec6a785c346b4
4
+ data.tar.gz: fc80d107f4372349a1dfcd105b9d35c82fd66e65d70bc226cad09dab2c7bbc5c
5
5
  SHA512:
6
- metadata.gz: 249d9724441d3a927679ed6e8c88a7e3944c7812efe0a787f656bab7878796452d6d6c46d96a69f1f793680521b2989ab972c30251eff5e38bbf54d0aedde2a9
7
- data.tar.gz: 53dc43080979cd573aae3ca906fe15abc4f61a07bcef3cdf15f6bde205766eabdeac76cb5b64aaa188af654012499161c40932708e788818a9050fd0e681e961
6
+ metadata.gz: 3fa3bacdbffb0325c849ace71cf41e2698486a9114ea5ac1cb7572cf2e1581072d422a3b17907f1f8b5d97678ce9e33df12b6b95e4f1acfe9d5bb66ed7e2ab81
7
+ data.tar.gz: c68e6a3bfe52b082a686016686f81b7a5976696d2abcd658b5501450e449eabfdcc1be41bfa1c9ba1403d3b1ea60d9504cba2770393705d8753d31a5d5c1b34e
@@ -1,18 +1,18 @@
1
- require "msngr/version"
2
- require "msngr/receiver"
3
- require "msngr/messenger"
4
-
5
1
  module Msngr
6
- module Clients; end
2
+ require "msngr/version"
3
+ require "msngr/clients"
4
+ require "msngr/receiver"
5
+ require "msngr/messenger"
6
+
7
7
  extend self
8
8
 
9
9
  # Shorthand for writing Msngr::Messenger.new(*args).
10
10
  #
11
11
  # @param [Array] *args
12
+ #
12
13
  # @return [Msngr::Messenger]
13
14
  #
14
15
  def new(*args)
15
16
  Messenger.new(*args)
16
17
  end
17
18
  end
18
-
@@ -0,0 +1,2 @@
1
+ module Msngr::Clients
2
+ end
@@ -44,4 +44,3 @@ class Msngr::Clients::Redis
44
44
  end
45
45
  end
46
46
  end
47
-
@@ -17,18 +17,20 @@ class Msngr::Messenger
17
17
  # Initializes a new Messenger.
18
18
  #
19
19
  # @param [Msngr::Clients::*] client the to receive messages from.
20
+ #
20
21
  # @return [Receiver]
21
22
  #
22
23
  def initialize(client)
23
- @client = client
24
+ @client = client
24
25
  @receivers = []
25
- @mutex = Mutex.new
26
+ @mutex = Mutex.new
26
27
  end
27
28
 
28
29
  # Creates and returns a new Receiver and adds it to @receivers so
29
30
  # it'll receive messages matching the provided pattern.
30
31
  #
31
32
  # @param [Regexp] pattern
33
+ #
32
34
  # @return [Receiver]
33
35
  #
34
36
  def subscribe(pattern)
@@ -100,4 +102,3 @@ class Msngr::Messenger
100
102
  callbacks.each { |callback| callback.call(*args) }
101
103
  end
102
104
  end
103
-
@@ -23,13 +23,14 @@ class Msngr::Receiver
23
23
  # Initializes a new Receiver.
24
24
  #
25
25
  # @param [Regexp] pattern the pattern to listen for.
26
+ #
26
27
  # @return [Receiver]
27
28
  #
28
29
  def initialize(pattern = /.+/)
29
- @pattern = pattern
30
- @on_message_callbacks = []
30
+ @pattern = pattern
31
+ @on_message_callbacks = []
31
32
  @on_unsubscribe_callbacks = []
32
- @mutex = Mutex.new
33
+ @mutex = Mutex.new
33
34
  end
34
35
 
35
36
  # Define a callback that invokes on each received message.
@@ -58,4 +59,3 @@ class Msngr::Receiver
58
59
  @mutex.synchronize { @on_unsubscribe_callbacks << block }
59
60
  end
60
61
  end
61
-
@@ -1,4 +1,3 @@
1
1
  module Msngr
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
4
-
@@ -6,37 +6,36 @@ describe Msngr::Clients::Redis do
6
6
  let(:client) { Msngr::Clients::Redis.new }
7
7
 
8
8
  it "should initialize without redis options" do
9
- client.should have(0).args
9
+ expect(client.args.count).to eq(0)
10
10
  end
11
11
 
12
12
  it "should initialize with arguments" do
13
13
  client = Msngr::Clients::Redis.new(host: "127.0.0.1", port: 6379)
14
- client.args.should == [{host: "127.0.0.1", port: 6379}]
14
+ expect(client.args).to eq([{host: "127.0.0.1", port: 6379}])
15
15
  end
16
16
 
17
17
  it "should establish a connection without any args" do
18
- Redis.expects(:new)
18
+ expect(Redis).to receive(:new)
19
19
  client.send(:connection)
20
20
  end
21
21
 
22
22
  it "should establish a connection with args" do
23
23
  options = { host: "127.0.0.1", port: 6379 }
24
24
  client = Msngr::Clients::Redis.new(options)
25
- Redis.expects(:new).with(options)
25
+ expect(Redis).to receive(:new).with(options)
26
26
  client.send(:connection)
27
27
  end
28
28
 
29
29
  it "should yield a message" do
30
- connection, on = mock, mock
30
+ connection, on = double, double
31
31
 
32
- client.stubs(:connection).returns(connection)
33
- connection.expects(:psubscribe).with("*").yields(on)
34
- on.expects(:pmessage).yields("", "room.1", "John joined the room!")
32
+ allow(client).to receive(:connection).and_return(connection)
33
+ expect(connection).to receive(:psubscribe).with("*").and_yield(on)
34
+ expect(on).to receive(:pmessage).and_yield("", "room.1", "John joined the room!")
35
35
 
36
36
  client.on_message do |event, message|
37
- event.should == "room.1"
38
- message.should == "John joined the room!"
37
+ expect(event).to eq("room.1")
38
+ expect(message).to eq("John joined the room!")
39
39
  end
40
40
  end
41
41
  end
42
-
@@ -4,53 +4,53 @@ require "msngr/messenger"
4
4
 
5
5
  describe Msngr::Messenger do
6
6
 
7
- let(:client) { mock }
7
+ let(:client) { double }
8
8
  let(:messenger) { Msngr::Messenger.new(client) }
9
9
 
10
10
  it "should initialize with an empty array of receivers" do
11
- messenger.receivers.should be_empty
11
+ expect(messenger.receivers).to be_empty
12
12
  end
13
13
 
14
14
  it "should create a new Receiver and add it to @receivers" do
15
15
  receiver = messenger.subscribe(/.+/)
16
- messenger.should have(1).receivers
17
- messenger.receivers.first.should == receiver
16
+ expect(messenger.receivers.count).to eq(1)
17
+ expect(messenger.receivers.first).to eq(receiver)
18
18
  end
19
19
 
20
20
  it "should unsubscribe a receiver" do
21
21
  receiver = messenger.subscribe(/.+/)
22
- messenger.expects(:dispatch).
23
- with(receiver.on_unsubscribe_callbacks, messenger)
22
+ expect(messenger).to receive(:dispatch)
23
+ .with(receiver.on_unsubscribe_callbacks, messenger)
24
24
  messenger.unsubscribe(receiver)
25
- messenger.should have(0).receivers
25
+ expect(messenger.receivers.count).to eq(0)
26
26
  end
27
27
 
28
28
  it "should start listening on a separate thread" do
29
- Thread.expects(:new).yields
30
- messenger.expects(:loop).yields
31
- messenger.expects(:listen).once
29
+ expect(Thread).to receive(:new).and_yield
30
+ expect(messenger).to receive(:loop).and_yield
31
+ expect(messenger).to receive(:listen).once
32
32
  messenger.listen!
33
33
  end
34
34
 
35
35
  it "should display a backtrace on error and restart" do
36
- Thread.expects(:new).yields
37
- messenger.expects(:loop).yields
38
- messenger.expects(:listen).raises.then.returns
39
- messenger.expects(:puts).times(4)
40
- messenger.expects(:sleep)
36
+ expect(Thread).to receive(:new).and_yield
37
+ expect(messenger).to receive(:loop).and_yield
38
+ expect(messenger).to receive(:listen).and_raise
39
+ expect(messenger).to receive(:puts).exactly(4).times
40
+ expect(messenger).to receive(:sleep)
41
41
  messenger.listen!
42
42
  end
43
43
 
44
44
  it "should listen to the client but not dispatch" do
45
45
  messenger.subscribe(/room\.2/)
46
- client.expects(:on_message).yields("room.1", "Hi John")
47
- messenger.expects(:dispatch).never
46
+ expect(client).to receive(:on_message).and_yield("room.1", "Hi John")
47
+ expect(messenger).to receive(:dispatch).never
48
48
  messenger.send(:listen)
49
49
  end
50
50
 
51
51
  it "should listen to the client and dispatch a message" do
52
- messenger.subscribe(/room\.1/).on_message { |m| m.should == "Hi John" }
53
- client.expects(:on_message).yields("room.1", "Hi John")
52
+ messenger.subscribe(/room\.1/).on_message { |m| expect(m).to eq("Hi John") }
53
+ expect(client).to receive(:on_message).and_yield("room.1", "Hi John")
54
54
  messenger.send(:listen)
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ describe Msngr::Messenger do
58
58
  3.times do
59
59
  messenger.subscribe(/room\.1/).tap do |receiver|
60
60
  cb = proc {}
61
- cb.expects(:call).with("Hi John")
61
+ expect(cb).to receive(:call).with("Hi John")
62
62
  receiver.on_message(&cb)
63
63
  end
64
64
  end
@@ -66,13 +66,12 @@ describe Msngr::Messenger do
66
66
  2.times do
67
67
  messenger.subscribe(/room\.2/).tap do |receiver|
68
68
  cb = proc {}
69
- cb.expects(:call).never
69
+ expect(cb).to receive(:call).never
70
70
  receiver.on_message(&cb)
71
71
  end
72
72
  end
73
73
 
74
- client.expects(:on_message).yields("room.1", "Hi John")
74
+ expect(client).to receive(:on_message).and_yield("room.1", "Hi John")
75
75
  messenger.send(:listen)
76
76
  end
77
77
  end
78
-
@@ -6,12 +6,12 @@ describe Msngr::Receiver do
6
6
  let(:receiver) { Msngr::Receiver.new }
7
7
 
8
8
  it "should initialize with a default wildcard pattern" do
9
- receiver.pattern.should == /.+/
9
+ expect(receiver.pattern).to eq(/.+/)
10
10
  end
11
11
 
12
12
  it "should initialize with a custom pattern" do
13
13
  pattern = /rooms\.1/
14
- Msngr::Receiver.new(pattern).pattern.should == pattern
14
+ expect(Msngr::Receiver.new(pattern).pattern).to eq(pattern)
15
15
  end
16
16
 
17
17
  it "should define an message callback" do
@@ -19,8 +19,8 @@ describe Msngr::Receiver do
19
19
  receiver.on_message(&callback)
20
20
 
21
21
  callbacks = receiver.on_message_callbacks
22
- callbacks.size.should == 1
23
- callbacks.first.call("message").should == "invoked: message"
22
+ expect(callbacks.size).to eq(1)
23
+ expect(callbacks.first.call("message")).to eq("invoked: message")
24
24
  end
25
25
 
26
26
  it "should define an unsubscribe callback" do
@@ -28,10 +28,9 @@ describe Msngr::Receiver do
28
28
  receiver.on_unsubscribe(&callback)
29
29
 
30
30
  callbacks = receiver.on_unsubscribe_callbacks
31
- callbacks.size.should == 1
31
+ expect(callbacks.size).to eq(1)
32
32
 
33
33
  object = Object.new
34
- callbacks.first.call(object).should == "unsubscribed from: #{object}"
34
+ expect(callbacks.first.call(object)).to eq("unsubscribed from: #{object}")
35
35
  end
36
36
  end
37
-
@@ -4,7 +4,6 @@ require "msngr"
4
4
  describe Msngr do
5
5
 
6
6
  it "should instantiate an instance of Msngr::Messenger" do
7
- Msngr.new(mock).class.should == Msngr::Messenger
7
+ expect(Msngr.new(double).class).to eq(Msngr::Messenger)
8
8
  end
9
9
  end
10
-
@@ -2,8 +2,3 @@ require "simplecov"
2
2
  require "bundler"
3
3
  SimpleCov.start
4
4
  Bundler.require
5
-
6
- RSpec.configure do |config|
7
- config.mock_with :mocha
8
- end
9
-
metadata CHANGED
@@ -1,58 +1,151 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msngr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: 10.4.2
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: 10.4.2
27
41
  - !ruby/object:Gem::Dependency
28
- name: rake
42
+ name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 10.1.0
34
- - - ">="
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
35
60
  - !ruby/object:Gem::Version
36
- version: 10.1.0
61
+ version: 0.10.1
37
62
  type: :development
38
63
  prerelease: false
39
64
  version_requirements: !ruby/object:Gem::Requirement
40
65
  requirements:
41
66
  - - "~>"
42
67
  - !ruby/object:Gem::Version
43
- version: 10.1.0
44
- - - ">="
68
+ version: 0.10.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.20.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.20.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: redis
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.2.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.2.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: hiredis
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: parallel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.3
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
45
137
  - !ruby/object:Gem::Version
46
- version: 10.1.0
138
+ version: 1.3.3
47
139
  description: A light-weight Ruby library for multi-threaded Ruby applications that
48
140
  allows threads to share a single service connection for more efficient messaging.
49
141
  email:
50
- - meskyanichi@gmail.com
142
+ - michael@vanrooijen.io
51
143
  executables: []
52
144
  extensions: []
53
145
  extra_rdoc_files: []
54
146
  files:
55
147
  - "./lib/msngr.rb"
148
+ - "./lib/msngr/clients.rb"
56
149
  - "./lib/msngr/clients/redis.rb"
57
150
  - "./lib/msngr/messenger.rb"
58
151
  - "./lib/msngr/receiver.rb"
@@ -62,7 +155,7 @@ files:
62
155
  - "./spec/lib/msngr/receiver_spec.rb"
63
156
  - "./spec/lib/msngr_spec.rb"
64
157
  - "./spec/spec_helper.rb"
65
- homepage: https://github.com/meskyanichi/msngr/
158
+ homepage: https://github.com/mrrooijen/msngr/
66
159
  licenses:
67
160
  - MIT
68
161
  metadata: {}
@@ -81,8 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
174
  - !ruby/object:Gem::Version
82
175
  version: '0'
83
176
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.2.0
177
+ rubygems_version: 3.1.2
86
178
  signing_key:
87
179
  specification_version: 4
88
180
  summary: A light-weight Ruby library for multi-threaded Ruby applications that allows