DEV: bump version

DEV: bump version

Also amends register_client_message_filter to be array based.

This avoids conditions where filters would override if you would register a duplicate filter.

diff --git a/CHANGELOG b/CHANGELOG
index a3d6836..ac863df 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
-Unreleased
-  - FEATURE: `MessageBus#register_client_message_filter` to register a custom filter so that messages can be inspected and filtered away from
-      clients.
+28-04-2020
+
+- Version 3.1.0
+
+  - FEATURE: `MessageBus#register_client_message_filter` to register a custom filter so that messages can be inspected and filtered away from clients.
 
 27-04-2020
 
diff --git a/lib/message_bus.rb b/lib/message_bus.rb
index 72ec9cf..181265d 100644
--- a/lib/message_bus.rb
+++ b/lib/message_bus.rb
@@ -563,14 +563,15 @@ module MessageBus::Implementation
   # @return [void]
   def register_client_message_filter(channel_prefix, &blk)
     if blk
-      configure(client_message_filters: {}) if !@config[:client_message_filters]
-      @config[:client_message_filters][channel_prefix] = blk
+      configure(client_message_filters: []) if !@config[:client_message_filters]
+      @config[:client_message_filters] << [channel_prefix, blk]
     end
   end
 
-  # @return [Hash] returns a hash of message filters that have been registered
+  # @return [Array] returns a hash of message filters that have been registered
   def client_message_filters
-    @config[:client_message_filters] || {}
+    configure(client_message_filters: []) if !@config[:client_message_filters]
+    @config[:client_message_filters]
   end
 
   private
diff --git a/lib/message_bus/client.rb b/lib/message_bus/client.rb
index 78c72f8..307505d 100644
--- a/lib/message_bus/client.rb
+++ b/lib/message_bus/client.rb
@@ -153,7 +153,11 @@ class MessageBus::Client
 
     filters_allowed = true
 
-    @bus.client_message_filters.each do |channel_prefix, blk|
+    len = @bus.client_message_filters.length
+    while len > 0
+      len -= 1
+      channel_prefix, blk = @bus.client_message_filters[len]
+
       if msg.channel.start_with?(channel_prefix)
         filters_allowed = blk.call(msg)
         break if !filters_allowed
diff --git a/lib/message_bus/version.rb b/lib/message_bus/version.rb
index decf152..d1121de 100644
--- a/lib/message_bus/version.rb
+++ b/lib/message_bus/version.rb
@@ -1,5 +1,5 @@
 # frozen_string_literal: true
 
 module MessageBus
-  VERSION = "3.0.0"
+  VERSION = "3.1.0"
 end
diff --git a/spec/lib/message_bus/client_spec.rb b/spec/lib/message_bus/client_spec.rb
index 38ec554..dcbf043 100644
--- a/spec/lib/message_bus/client_spec.rb
+++ b/spec/lib/message_bus/client_spec.rb
@@ -352,33 +352,35 @@ describe MessageBus::Client do
       end
 
       describe 'when MessageBus#client_message_filters has been configured' do
-        before do
-          @message = MessageBus::Message.new(1, 2, '/test/5', 'hello')
-          @client.allowed?(@message).must_equal(true)
-        end
 
         it 'filters messages correctly' do
-          @bus.register_client_message_filter('/test') do |message|
-            message.data != 'hello'
+          message = MessageBus::Message.new(1, 2, '/test/5', 'hello')
+          @client.allowed?(message).must_equal(true)
+
+          @bus.register_client_message_filter('/test') do |m|
+            m.data != 'hello'
           end
 
-          @client.allowed?(@message).must_equal(false)
+          @client.allowed?(message).must_equal(false)
         end
 
         it 'filters messages correctly when multiple filters have been configured' do
-          called = false
+
+          bob_message = MessageBus::Message.new(1, 2, '/test/5', 'bob')
+          fred_message = MessageBus::Message.new(1, 2, '/test/5', 'fred')
+          random_message = MessageBus::Message.new(1, 2, '/test/77', 'random')
 
           @bus.register_client_message_filter('/test') do |message|
-            message.data == 'hello'
+            message.data == 'bob' || message.data == 'fred'
           end
 
-          @bus.register_client_message_filter('/tes') do |message|
-            called = true
-            message.data != 'hello'
+          @bus.register_client_message_filter('/test') do |message|
+            message.data == 'fred'
           end
 
-          @client.allowed?(@message).must_equal(false)
-          called.must_equal(true)
+          @client.allowed?(fred_message).must_equal(true)
+          @client.allowed?(bob_message).must_equal(false)
+          @client.allowed?(random_message).must_equal(false)
         end
       end
     end
diff --git a/spec/lib/message_bus_spec.rb b/spec/lib/message_bus_spec.rb
index 20d5435..366fc87 100644
--- a/spec/lib/message_bus_spec.rb
+++ b/spec/lib/message_bus_spec.rb
@@ -297,11 +297,14 @@ describe MessageBus do
     it 'should register the message filter correctly' do
       @bus.register_client_message_filter('/test')
 
-      @bus.client_message_filters.must_equal({})
+      @bus.client_message_filters.must_equal([])
 
       @bus.register_client_message_filter('/test') { puts "hello world" }
 
-      @bus.client_message_filters['/test'].must_respond_to(:call)
+      channel, blk = @bus.client_message_filters[0]
+
+      blk.must_respond_to(:call)
+      channel.must_equal('/test')
     end
   end
 end

GitHub sha: ff5cb9f1