emque-producing 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04dad235902569dfe2b4138e0f416ea3b5d21f03
4
- data.tar.gz: 213c7bdb4a81ab863de5e045dce4f957a7a9b6ff
3
+ metadata.gz: 34b5dbcad9ac87bf9f2e32837ae1b0df86106cd2
4
+ data.tar.gz: c1d60b701ae51322e96dfbb28a5cebdc90b66cc9
5
5
  SHA512:
6
- metadata.gz: e455013e439cf2c5b425c8dc21c3a1a8dc0cd4459b65169dc45fd0c7adf18f58d393d9545711b02618c7404f9cf3631d3806f48524fde184ae4c0a91c4064055
7
- data.tar.gz: f8dd1c09fa37006e90358ddcb2d6cfb97208a9c7dfa991c5a9397cc0b28425f29af974e17c09ccf0e1be692680695a52384d4fdbb4b1cdab9145d24cbca26cea
6
+ metadata.gz: 195424f83e156b10c86730e3e3f0936169e830ba244ad673f5bb524f61c5a064bea1d347f9f922dff75eefaddba2294abb6f6bc2d8796e19fd068fa0172a305e
7
+ data.tar.gz: ded8c20b8536c796da590660914f6f7a76f8b17088c14645906ca7ff77db98538a9944e6014acba4ccb4fdceed490f88b1bd7eda686c0540c4501399f9fcb7e6
@@ -6,6 +6,9 @@ rvm:
6
6
  - 2.2.2
7
7
  - rbx-2
8
8
  script: bundle exec rake
9
+ install:
10
+ - "gem install bundler"
11
+ - "bundle install --jobs=3 --retry=3"
9
12
  notifications:
10
13
  recipients:
11
14
  - shane@teamsnap.com
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- [ ![Codeship Status for
2
- teamsnap/emque-producing](https://www.codeship.io/projects/2ca7fd90-1785-0132-5f9d-7ab39a5c8237/status)](https://www.codeship.io/projects/34115)
1
+ [![Build Status](https://travis-ci.org/emque/emque-producing.png)](https://travis-ci.org/emque/emque-producing)
3
2
 
4
3
  # Emque Producing
5
4
 
@@ -1,5 +1,7 @@
1
1
  module Emque
2
2
  module Producing
3
+ ConfigurationError = Class.new(StandardError)
4
+
3
5
  class Configuration
4
6
  attr_accessor :app_name
5
7
  attr_accessor :publishing_adapter
@@ -8,6 +10,7 @@ module Emque
8
10
  attr_accessor :publish_messages
9
11
  attr_reader :rabbitmq_options
10
12
  attr_accessor :ignored_exceptions
13
+ attr_reader :middleware
11
14
 
12
15
  def initialize
13
16
  @app_name = ""
@@ -19,6 +22,19 @@ module Emque
19
22
  :url => "amqp://guest:guest@localhost:5672"
20
23
  }
21
24
  @ignored_exceptions = [Emque::Producing::Message::MessagesNotSentError]
25
+ @middleware = []
26
+ end
27
+
28
+ def use(callable)
29
+ unless callable.respond_to?(:call) and callable.arity == 1
30
+ raise(
31
+ ConfigurationError,
32
+ "#{self.class.name}#use must receive a callable object with an " +
33
+ "arity of one."
34
+ )
35
+ end
36
+
37
+ @middleware << callable
22
38
  end
23
39
  end
24
40
  end
@@ -20,6 +20,10 @@ module Emque
20
20
  @message_type = name
21
21
  end
22
22
 
23
+ def middleware
24
+ @middleware || []
25
+ end
26
+
23
27
  def read_message_type
24
28
  @message_type
25
29
  end
@@ -53,6 +57,19 @@ module Emque
53
57
  def private_attrs
54
58
  Array(@private_attrs)
55
59
  end
60
+
61
+ def use(callable)
62
+ unless callable.respond_to?(:call) and callable.arity == 1
63
+ raise(
64
+ ConfigurationError,
65
+ "#{self.class.name}#use must receive a callable object with an " +
66
+ "arity of one."
67
+ )
68
+ end
69
+
70
+ @middleware ||= []
71
+ @middleware << callable
72
+ end
56
73
  end
57
74
 
58
75
  def self.included(base)
@@ -115,7 +132,8 @@ module Emque
115
132
  if valid?
116
133
  log "valid...", true
117
134
  if Emque::Producing.configuration.publish_messages
118
- sent = publisher.publish(topic, message_type, to_json, partition_key)
135
+ message = process_middleware(to_json)
136
+ sent = publisher.publish(topic, message_type, message, partition_key)
119
137
  log "sent #{sent}"
120
138
  raise MessagesNotSentError.new unless sent
121
139
  end
@@ -166,6 +184,24 @@ module Emque
166
184
  end
167
185
  end
168
186
 
187
+ def middleware
188
+ self.class.middleware + Emque::Producing.configuration.middleware
189
+ end
190
+
191
+ def middleware?
192
+ middleware.count > 0
193
+ end
194
+
195
+ def process_middleware(str)
196
+ if middleware?
197
+ middleware.inject(str) { |compiled, callable|
198
+ callable.call(compiled)
199
+ }
200
+ else
201
+ str
202
+ end
203
+ end
204
+
169
205
  def public_attributes
170
206
  public = self.class.attribute_set.select do |attr|
171
207
  attr && !self.class.private_attrs.include?(attr.name)
@@ -1,5 +1,5 @@
1
1
  module Emque
2
2
  module Producing
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -18,4 +18,34 @@ describe Emque::Producing::Configuration do
18
18
  subject.rabbitmq_options = {:requires_confirmation => false}
19
19
  }.to raise_error
20
20
  end
21
+
22
+ describe "middleware" do
23
+ it "does not allow direct assignment" do
24
+ expect {
25
+ subject.middleware = proc { |_| true }
26
+ }.to raise_error
27
+ end
28
+
29
+ it "#use raises a ConfigurationError if the first arg is not callable" do
30
+ expect {
31
+ subject.use("not callable")
32
+ }.to raise_error Emque::Producing::ConfigurationError
33
+ end
34
+
35
+ it "#use raises a ConfigurationError if the first arg's arity is not 1" do
36
+ expect {
37
+ subject.use(proc { true })
38
+ }.to raise_error Emque::Producing::ConfigurationError
39
+
40
+ expect {
41
+ subject.use(proc { |_, _| true })
42
+ }.to raise_error Emque::Producing::ConfigurationError
43
+ end
44
+
45
+ it "#use adds a valid callable object to the middleware stack" do
46
+ expect(subject.middleware.count).to eq 0
47
+ subject.use(proc { |_| true })
48
+ expect(subject.middleware.count).to eq 1
49
+ end
50
+ end
21
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emque-producing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emily Dobervich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-05 00:00:00.000000000 Z
12
+ date: 2016-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oj
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
- rubygems_version: 2.4.5
176
+ rubygems_version: 2.4.5.1
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: Define and send messages to a variety of message brokers
@@ -183,3 +183,4 @@ test_files:
183
183
  - spec/producing/message/message_spec.rb
184
184
  - spec/producing/producing_spec.rb
185
185
  - spec/spec_helper.rb
186
+ has_rdoc: