amqp_topic_binding 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b76a01c88917457f86c49bd2b5cc166a9928352d
4
+ data.tar.gz: b6fc354ee12a0863f809c6b5c3816e2e31a7ec2d
5
+ SHA512:
6
+ metadata.gz: c51459f6d7930074500b3d53bf214dd242be670477c6168c894a1486fd69652664f7b83d45837596e4bdc6e9a54d395650736eba5d48654655c839e758f35bfe
7
+ data.tar.gz: cd7a98eb88974a4e4747492a0f6a212e4c916dc78ab1a38c6cb78dd2f7e9ebdc912b0e825a97389822f906417c30d5f6f8bec2e20041da4575dc47f8ce0bdc95
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in amqp_topic_binding.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ # AmqpTopicBinding
2
+
3
+ This simple gem implements the matching algorithm for AMQP topic exchange
4
+ routing key bindings, allowing you to do the same matching that is performed
5
+ at the exchange when the broker is deciding what to send to a queue.
6
+
7
+ Wildcards are supported.
8
+
9
+ ## Usage
10
+
11
+ Simply ask the matcher if a routing key matches a pattern:
12
+
13
+ ```ruby
14
+ > AmqpTopicBinding::Matcher.new('foo.bar.*').matches?('foo.bar.baz')
15
+ => true
16
+ > AmqpTopicBinding::Matcher.new('foo.bar.*').matches?('foo.bar')
17
+ => false
18
+ > AmqpTopicBinding::Matcher.new('foo.#').matches?('foo.bar.baz')
19
+ => true
20
+ ```
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'amqp_topic_binding/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "amqp_topic_binding"
8
+ spec.version = AmqpTopicBinding::VERSION
9
+ spec.authors = ["Rusty Geldmacher"]
10
+ spec.email = ["russell.geldmacher@gmail.com"]
11
+
12
+ spec.summary = %q{A matcher for the AMQP topic binding algorithm}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/rustygeldmacher/amqp_topic_binding"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "amqp_topic_binding"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require 'amqp_topic_binding/version'
2
+ require 'amqp_topic_binding/matcher'
@@ -0,0 +1,46 @@
1
+ module AmqpTopicBinding
2
+ class Matcher
3
+ def initialize(pattern)
4
+ @pattern = pattern || ''
5
+ @pattern_parts = @pattern.split('.')
6
+ end
7
+
8
+ def matches?(routing_key)
9
+ if routing_key.nil? || routing_key == ''
10
+ return false
11
+ end
12
+
13
+ if @pattern == routing_key
14
+ return true
15
+ end
16
+
17
+ routing_key_parts = routing_key.split('.')
18
+
19
+ if @pattern_parts.length > routing_key_parts.length
20
+ return false
21
+ end
22
+
23
+ last_checked_index = 0
24
+
25
+ @pattern_parts.each_with_index do |pattern_part, index|
26
+ if pattern_part == '#'
27
+ return true
28
+ end
29
+
30
+ routing_key_part = routing_key_parts[index]
31
+
32
+ if pattern_part != '*' && pattern_part != routing_key_part
33
+ return false
34
+ end
35
+
36
+ last_checked_index = index
37
+ end
38
+
39
+ if routing_key_parts.length > (last_checked_index + 1)
40
+ return false
41
+ end
42
+
43
+ return true
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module AmqpTopicBinding
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amqp_topic_binding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rusty Geldmacher
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A matcher for the AMQP topic binding algorithm
56
+ email:
57
+ - russell.geldmacher@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - amqp_topic_binding.gemspec
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/amqp_topic_binding.rb
70
+ - lib/amqp_topic_binding/matcher.rb
71
+ - lib/amqp_topic_binding/version.rb
72
+ homepage: https://github.com/rustygeldmacher/amqp_topic_binding
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.7
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A matcher for the AMQP topic binding algorithm
95
+ test_files: []