rabbitmq-spec 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.yardopts +3 -0
- data/Gemfile +2 -0
- data/README.md +9 -0
- data/lib/rabbitmq-spec.rb +1 -0
- data/lib/rabbitmq-spec/dsl.rb +12 -0
- data/lib/rabbitmq-spec/dsl/builder.rb +3 -0
- data/lib/rabbitmq-spec/dsl/builder/base.rb +27 -0
- data/lib/rabbitmq-spec/dsl/builder/exchange.rb +1 -0
- data/lib/rabbitmq-spec/dsl/builder/queue.rb +1 -0
- data/lib/rabbitmq-spec/dsl/world.rb +18 -0
- data/lib/rabbitmq-spec/entity.rb +1 -0
- data/lib/rabbitmq-spec/entity/exchange.rb +6 -0
- data/lib/rabbitmq-spec/entity/queue.rb +6 -0
- data/lib/rabbitmq-spec/setup.rb +8 -2
- data/lib/rabbitmq-spec/setup/runner.rb +12 -2
- data/lib/rabbitmq-spec/setup/world_fetcher.rb +5 -0
- data/lib/rabbitmq-spec/setup/world_setupper.rb +12 -0
- data/lib/rabbitmq-spec/version.rb +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 016cfd923683057289d676445546b13f59314f89
|
4
|
+
data.tar.gz: da4ce486cd8e02f41bd3dc7d7b1573b3e8659d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16270c70679b6eeb18689da2f88b07139e89024d3d6e572d0372a4e7d0bcb2949f104802c306ad12d0060d2a41c5bb456cd58835be8308bc8835eb9a5ad4fd81
|
7
|
+
data.tar.gz: 04607f00200dc540f61875d2a81f26e1101e3d7d1b5f45016e614f6c762f1caa575852ef0d37307a9edb379922d28f34249b2f96324fc794fa00595ffe150b01
|
data/.rubocop.yml
CHANGED
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -74,6 +74,15 @@ On each mqspec file. You can use the following syntax:
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
# you can declare queues outside exchanges.
|
79
|
+
# The setup process will not bind them to anything
|
80
|
+
queue 'queue-name' do
|
81
|
+
description 'queue1 description'
|
82
|
+
options do
|
83
|
+
durable true
|
84
|
+
end
|
85
|
+
end
|
77
86
|
`````
|
78
87
|
|
79
88
|
## RabbitMQ Setup
|
data/lib/rabbitmq-spec.rb
CHANGED
data/lib/rabbitmq-spec/dsl.rb
CHANGED
@@ -1,7 +1,19 @@
|
|
1
|
+
# Namespace for all DSL logic.
|
2
|
+
# Use this module to evaluate a string in our DSL format
|
3
|
+
# and fetch a world instance containing all the entities extracted
|
4
|
+
# from the DSL specification
|
5
|
+
# @example
|
6
|
+
# RabbitMQSpec::DSL.evaluate(%Q{
|
7
|
+
# exchange 'name1' do
|
8
|
+
# description %Q{ My Exchange }
|
9
|
+
# end
|
10
|
+
# })
|
1
11
|
module RabbitMQSpec::DSL
|
2
12
|
autoload :World, 'rabbitmq-spec/dsl/world'
|
3
13
|
autoload :Builder, 'rabbitmq-spec/dsl/builder'
|
4
14
|
|
15
|
+
# @param dsl String in the DSL format to be evaluated by.
|
16
|
+
# @return [World] Configured by the DSL definition.
|
5
17
|
def self.evaluate(dsl)
|
6
18
|
world = World.new
|
7
19
|
world.instance_eval(dsl)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# @api private
|
2
|
+
# Namespace for all DSL builders.
|
3
|
+
# Each builder is a class that implements the methods that are called when evaluating the DSL
|
1
4
|
class RabbitMQSpec::DSL::Builder
|
2
5
|
autoload :Base, 'rabbitmq-spec/dsl/builder/base'
|
3
6
|
autoload :Queue, 'rabbitmq-spec/dsl/builder/queue'
|
@@ -1,22 +1,44 @@
|
|
1
|
+
# Base class for each builder.
|
2
|
+
# A Builder is a class where the DSL evaluator will run
|
3
|
+
# the DSL files. It is where we define our DSL syntax.
|
4
|
+
# For more info to know how to use it,
|
5
|
+
# see the specs related to the builders.
|
1
6
|
class RabbitMQSpec::DSL::Builder::Base
|
2
7
|
# class methods
|
8
|
+
|
9
|
+
# @private
|
10
|
+
# Helper method to inhereted classes.
|
11
|
+
# We declare witch methods will be allowed to be called
|
12
|
+
# inside a builder instance in order to store the value
|
13
|
+
# passed to the method
|
3
14
|
def self.define_dsl_attribute(attribute_name)
|
4
15
|
@allowed_dsl_attributes ||= []
|
5
16
|
@allowed_dsl_attributes << attribute_name.to_sym
|
6
17
|
end
|
7
18
|
|
19
|
+
# @private
|
20
|
+
# Helper method to inhereted classes.
|
21
|
+
# The child class must call this method
|
22
|
+
# Passing and entity to be builded after
|
23
|
+
# all the the attributes was filled
|
8
24
|
def self.define_entity_class(entity_class)
|
9
25
|
@entity_class = entity_class
|
10
26
|
end
|
11
27
|
|
28
|
+
# @private
|
12
29
|
def self.get_entity_class
|
13
30
|
@entity_class
|
14
31
|
end
|
15
32
|
|
33
|
+
# @private
|
16
34
|
def self.has_dsl_attribute?(attribute_name)
|
17
35
|
@allowed_dsl_attributes.include?(attribute_name.to_sym)
|
18
36
|
end
|
19
37
|
|
38
|
+
# @public
|
39
|
+
# This method evaluates the given blog inside
|
40
|
+
# a new instance of the Builder class
|
41
|
+
# and asks for the class to build the correlated entity
|
20
42
|
def self.build(default_entity_values = {}, &block)
|
21
43
|
builder = new(default_entity_values)
|
22
44
|
builder.instance_eval(&block)
|
@@ -28,6 +50,9 @@ class RabbitMQSpec::DSL::Builder::Base
|
|
28
50
|
@builded_attributes = {}.merge(default_entity_values)
|
29
51
|
end
|
30
52
|
|
53
|
+
# For each method called we verify if it's
|
54
|
+
# an defined attribute for the builder.
|
55
|
+
# If it is then we store the argument as value of the attribute
|
31
56
|
def method_missing(method_name, *args, &block)
|
32
57
|
if self.class.has_dsl_attribute?(method_name.to_sym)
|
33
58
|
@builded_attributes[method_name.to_sym] = if block_given?
|
@@ -51,6 +76,8 @@ class RabbitMQSpec::DSL::Builder::Base
|
|
51
76
|
|
52
77
|
private
|
53
78
|
|
79
|
+
# Helper class to evaluate blocks that are passe
|
80
|
+
# to the defined attributes for the inhereted classes
|
54
81
|
class HashBuilder
|
55
82
|
def initialize
|
56
83
|
@hash = {}
|
@@ -1,12 +1,30 @@
|
|
1
|
+
# Class to generate instances for the DSL evaluation
|
2
|
+
# @api private
|
3
|
+
# @attr exchanges [Array<RabbitMQSpec::Entity::Exchange>]
|
4
|
+
# @attr single_queues [Array<RabbitMQSpec::Entity::Queue>]
|
5
|
+
|
1
6
|
class RabbitMQSpec::DSL::World
|
2
7
|
attr_reader :exchanges
|
8
|
+
attr_reader :single_queues
|
3
9
|
|
4
10
|
def initialize
|
5
11
|
@exchanges = []
|
12
|
+
@single_queues = []
|
6
13
|
end
|
7
14
|
|
15
|
+
# DSL exchange keyword
|
16
|
+
# @attr name [String] Name of the exchange
|
17
|
+
# @yield Block to be evaluated on RabbitMQSpec::DSL::Builder::Exchange build proccess
|
8
18
|
def exchange(name, &block)
|
9
19
|
new_exchange = RabbitMQSpec::DSL::Builder::Exchange.build(name: name, &block)
|
10
20
|
@exchanges << new_exchange
|
11
21
|
end
|
22
|
+
|
23
|
+
# DSL queue keyword
|
24
|
+
# @attr name [String] Name of the queue
|
25
|
+
# @yield Block to be evaluated on RabbitMQSpec::DSL::Builder::Exchange build proccess
|
26
|
+
def queue(name, &block)
|
27
|
+
new_queue = RabbitMQSpec::DSL::Builder::Queue.build(name: name, &block)
|
28
|
+
@single_queues << new_queue
|
29
|
+
end
|
12
30
|
end
|
data/lib/rabbitmq-spec/entity.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# Represents an exchange in the AMPQ broker
|
2
|
+
# @attr name [String]
|
3
|
+
# @attr description [String]
|
4
|
+
# @attr queues [Array<RabbitMQSpec::Entity::Queue>]
|
5
|
+
# @attr options [Hash] Configuration options
|
6
|
+
|
1
7
|
class RabbitMQSpec::Entity::Exchange
|
2
8
|
attr_accessor :name
|
3
9
|
attr_accessor :description
|
data/lib/rabbitmq-spec/setup.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'bunny'
|
2
2
|
|
3
|
+
# Does the AMPQ Broker setup by reading all mqspecs files,
|
4
|
+
# evaluating them and connecting to the broker using the provided url
|
5
|
+
# in order to create all exchanges, queues and bindings
|
6
|
+
# @example
|
7
|
+
# RabbitMQSpec::Setup.run(['/my/path/folde1', 'my/direct_mqspec/file.rb'], 'amqp://guest:guest@localhost:5672')
|
3
8
|
class RabbitMQSpec::Setup
|
4
9
|
autoload :Runner, 'rabbitmq-spec/setup/runner'
|
5
10
|
autoload :WorldSetupper, 'rabbitmq-spec/setup/world_setupper'
|
@@ -12,6 +17,7 @@ class RabbitMQSpec::Setup
|
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
20
|
+
# @private
|
15
21
|
def with_client(ampq_broker_url)
|
16
22
|
client = Bunny.new(ampq_broker_url, automatically_recover: false)
|
17
23
|
channel = nil
|
@@ -22,8 +28,8 @@ class RabbitMQSpec::Setup
|
|
22
28
|
rescue Exception => ex
|
23
29
|
raise ex
|
24
30
|
ensure
|
25
|
-
channel
|
26
|
-
client
|
31
|
+
channel && channel.close
|
32
|
+
client && client.close
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -1,3 +1,12 @@
|
|
1
|
+
# @api private
|
2
|
+
# Read each file and setups RabbitMQ based on
|
3
|
+
# each mqspec defined on them
|
4
|
+
# @example
|
5
|
+
# RabbitMQSpec::Setup::Runner.run(
|
6
|
+
# [
|
7
|
+
# '/my/path/folde1',
|
8
|
+
# 'my/direct_mqspec/file.rb']
|
9
|
+
# ], bunny_client)
|
1
10
|
class RabbitMQSpec::Setup::Runner
|
2
11
|
def initialize(paths_to_read, client)
|
3
12
|
@paths_to_read = paths_to_read
|
@@ -10,11 +19,12 @@ class RabbitMQSpec::Setup::Runner
|
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
13
|
-
|
22
|
+
# private methods
|
23
|
+
private def worlds
|
14
24
|
@paths_to_read.map { |path| RabbitMQSpec::Setup::WorldFetcher.call(path) }
|
15
25
|
end
|
16
26
|
|
17
|
-
def setup_world(world)
|
27
|
+
private def setup_world(world)
|
18
28
|
RabbitMQSpec::Setup::WorldSetupper.call(world, @client)
|
19
29
|
end
|
20
30
|
end
|
@@ -1,9 +1,17 @@
|
|
1
|
+
# @api private
|
2
|
+
# It uses the client to configure the RabbitMQ
|
3
|
+
# according with the world object
|
4
|
+
# @example
|
5
|
+
# RabbitMQSpec::Setup::WorldSetupper.(world, client)
|
1
6
|
module RabbitMQSpec::Setup::WorldSetupper
|
2
7
|
class << self
|
3
8
|
def call(world, client)
|
4
9
|
world.exchanges.each do |exchange|
|
5
10
|
setup_exchange(exchange, client)
|
6
11
|
end
|
12
|
+
world.single_queues.each do |queue|
|
13
|
+
setup_queue(queue, client)
|
14
|
+
end
|
7
15
|
end
|
8
16
|
|
9
17
|
def setup_exchange(exchange, client)
|
@@ -17,5 +25,9 @@ module RabbitMQSpec::Setup::WorldSetupper
|
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
28
|
+
|
29
|
+
def setup_queue(queue, client)
|
30
|
+
client.queue(queue.name, queue.options)
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitmq-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinicius Oyama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cri
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- ".ruby-gemset"
|
140
140
|
- ".ruby-version"
|
141
141
|
- ".travis.yml"
|
142
|
+
- ".yardopts"
|
142
143
|
- Gemfile
|
143
144
|
- LICENSE.txt
|
144
145
|
- README.md
|
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
184
|
version: '0'
|
184
185
|
requirements: []
|
185
186
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.6.
|
187
|
+
rubygems_version: 2.6.12
|
187
188
|
signing_key:
|
188
189
|
specification_version: 4
|
189
190
|
summary: Gem for documenting and configuring RabbitMQ brokers.
|