lapine 2.0.0 → 2.0.2

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
2
  SHA1:
3
- metadata.gz: 156563cfc5807e744c6713e272719901fb88f280
4
- data.tar.gz: acac0fa6b44c79629779ddef980762f2c7709bbe
3
+ metadata.gz: 6a1ec7e5fe596da8c60c447bedcf05df5cb36175
4
+ data.tar.gz: 2ba20e536b210ee4ca0070ee8484adb056be88cb
5
5
  SHA512:
6
- metadata.gz: 11aa3fbc86af8a1fac6c4a0001bf0a540d8d234b4b89f242119201628c93ddc88beaecd5912faee3d629e3c597cdcc9d130b682c84c242b88b6166f3e2878ace
7
- data.tar.gz: 08976cc67829c9539ed52bc8d0cc32a6d168f561172d322e1400c984b9fbb8b7ac980737692d56ab77c47dba94de0da41ecc628695b8e7f0948e19aabc51f1e4
6
+ metadata.gz: e009b311553286719e4299230afae8ceb8a037dfac712693d3e3d164dbb92eaac83f7162d6773d2994c89a731487b9afcf61fe02a93b31719f6de9a355f8c565
7
+ data.tar.gz: 88c9495d300d4963da640166366913513ef3bc11861539fed3b5afada498b5bdf952e449ceb47cbb16859e628d73542cc5397f8da6b60b2764e69c8dcad2c40b
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Lapine
2
2
  ======
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/lapine.svg)](http://badge.fury.io/rb/lapine)
5
+
4
6
  Speak to RabbitMQ. This gem serves as a wrapper for publishing messages
5
7
  to RabbitMQ via the Bunny gem, and for consuming messages using the AMQP
6
8
  gem.
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['dev@wanelo.com']
11
11
  spec.summary = %q{Talk to rabbits}
12
12
  spec.description = %q{Talk to rabbits}
13
- spec.homepage = 'https://github.com/wanelo/lapine'
13
+ spec.homepage = 'https://github.com/messagebus/lapine'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -20,13 +20,15 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'amqp'
22
22
  spec.add_dependency 'bunny'
23
+ spec.add_dependency 'environmenter', '~> 0.1'
24
+ spec.add_dependency 'middlewear', '~> 0.1'
23
25
  spec.add_dependency 'mixlib-cli'
24
26
  spec.add_dependency 'oj'
25
27
  spec.add_dependency 'ruby-usdt', '>= 0.2.2'
26
28
 
27
29
  spec.add_development_dependency 'bundler', '~> 1.7'
28
- spec.add_development_dependency 'guard-rspec', '~> 4.3.1'
30
+ spec.add_development_dependency 'guard-rspec', '~> 4.3'
29
31
  spec.add_development_dependency 'rake', '~> 10.0'
30
- spec.add_development_dependency 'rspec', '~> 3.1.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.1'
31
33
  spec.add_development_dependency 'em-spec'
32
34
  end
@@ -1,6 +1,7 @@
1
1
  require 'lapine/consumer/middleware/error_handler'
2
2
  require 'lapine/consumer/middleware/message_ack_handler'
3
3
  require 'lapine/consumer/middleware/json_decoder'
4
+ require 'middlewear'
4
5
 
5
6
  module Lapine
6
7
  module Consumer
@@ -28,101 +29,16 @@ module Lapine
28
29
  # end
29
30
  #
30
31
  module Middleware
31
- # A Register of a middleware class that messages will be passed through
32
- # on the way to being dispatched.
33
- class Register < Struct.new(:klass, :args)
34
- def create_new(app)
35
- klass.new(app, *args)
36
- end
37
- end
32
+ include Middlewear
38
33
 
39
34
  DEFAULT_MIDDLEWARE = [
40
- Register.new(MessageAckHandler),
41
- Register.new(ErrorHandler),
42
- Register.new(JsonDecoder)
35
+ MessageAckHandler,
36
+ ErrorHandler,
37
+ JsonDecoder
43
38
  ].freeze
44
39
 
45
- class << self
46
- def add(klass, *args)
47
- registry << [klass, args]
48
- end
49
-
50
- def add_before(before_klass, klass, *args)
51
- idx = registry.index_of(before_klass)
52
- raise MiddlewareNotFound.new("#{before_klass} not registered in Lapine middleware") unless idx
53
- registry.insert(idx, klass, args)
54
- end
55
-
56
- def add_after(after_klass, klass, *args)
57
- idx = registry.index_of(after_klass)
58
- raise MiddlewareNotFound.new("#{after_klass} not registered in Lapine middleware") unless idx
59
- registry.insert(idx + 1, klass, args)
60
- end
61
-
62
- def delete(klass)
63
- registry.delete(klass)
64
- end
65
-
66
- def registry
67
- @registry ||= Registry.new(DEFAULT_MIDDLEWARE.dup)
68
- end
69
-
70
- def create_chain(app)
71
- registry.map { |r| r.create_new(app) }
72
- end
73
-
74
- def app
75
- App.new.tap do |app|
76
- app.chain = create_chain(app)
77
- end
78
- end
79
- end
80
-
81
- class App
82
- attr_accessor :chain
83
-
84
- def call(message, &block)
85
- chain << block if block_given?
86
- current_register = chain.shift
87
- current_register.call(message) if current_register
88
- end
89
- end
90
-
91
- # Registry holds records of each middleware class that is added to the
92
- # consumer middleware chain.
93
- class Registry
94
- include Enumerable
95
-
96
- attr_reader :registry
97
-
98
- def initialize(registry = [])
99
- @registry = registry
100
- end
101
-
102
- def all
103
- registry
104
- end
105
-
106
- def each(&blk)
107
- all.each(&blk)
108
- end
109
-
110
- def delete(klass)
111
- registry.reject! { |register| register.klass == klass }
112
- end
113
-
114
- def <<(klass_args)
115
- insert(-1, klass_args[0], klass_args[1])
116
- end
117
-
118
- def index_of(klass)
119
- registry.find_index { |register| register.klass == klass }
120
- end
121
-
122
- def insert(index, klass, args)
123
- raise Lapine::DuplicateMiddleware if index_of(klass)
124
- registry.insert(index, Register.new(klass, args))
125
- end
40
+ DEFAULT_MIDDLEWARE.each do |middleware|
41
+ Lapine::Consumer::Middleware.add(middleware)
126
42
  end
127
43
  end
128
44
  end
@@ -1,10 +1,10 @@
1
1
  require 'amqp'
2
2
  require 'digest'
3
+ require 'environmenter'
3
4
  require 'eventmachine'
4
5
  require 'lapine/annotated_logger'
5
6
  require 'lapine/consumer/config'
6
7
  require 'lapine/consumer/connection'
7
- require 'lapine/consumer/environment'
8
8
  require 'lapine/consumer/message'
9
9
  require 'lapine/consumer/middleware'
10
10
  require 'lapine/consumer/topology'
@@ -23,7 +23,7 @@ module Lapine
23
23
 
24
24
  def run
25
25
  handle_signals!
26
- Consumer::Environment.new(config).load!
26
+ Environmenter::Loader.new(config).load!
27
27
  logger.info 'starting Lapine::Consumer'
28
28
 
29
29
  @queue_properties = queue_properties
@@ -1,3 +1,3 @@
1
1
  module Lapine
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -72,7 +72,7 @@ RSpec.describe Lapine::Consumer::Middleware do
72
72
  Lapine::Consumer::Middleware.tap do |middleware|
73
73
  middleware.add MiddlewareAddLetter, 'f'
74
74
  end
75
- }.to raise_error(Lapine::DuplicateMiddleware)
75
+ }.to raise_error(Middlewear::DuplicateMiddleware)
76
76
  end
77
77
  end
78
78
  end
@@ -97,6 +97,12 @@ RSpec.describe Lapine::Consumer::Middleware do
97
97
  describe 'with default middleware' do
98
98
  let(:error) { StandardError.new('doh') }
99
99
 
100
+ before do
101
+ Lapine::Consumer::Middleware::DEFAULT_MIDDLEWARE.each do |mw|
102
+ Lapine::Consumer::Middleware.add(mw)
103
+ end
104
+ end
105
+
100
106
  it 'runs through the dispatcher error_handler' do
101
107
  errors = []
102
108
  Lapine::Consumer::Dispatcher.error_handler = ->(e, data, md) {
@@ -24,7 +24,7 @@ RSpec.configure do |config|
24
24
  config.before :each do
25
25
  Lapine::Consumer::Dispatcher.error_handler = nil
26
26
  Lapine.instance_variable_set(:@config, nil)
27
- Lapine::Consumer::Middleware.instance_variable_set(:@registry,nil)
27
+ Lapine::Consumer::Middleware.instance_variable_set(:@registry, nil)
28
28
  Thread.current.thread_variable_set(:lapine_exchanges, nil)
29
29
  end
30
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lapine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Saxby
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-01 00:00:00.000000000 Z
12
+ date: 2016-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
@@ -39,6 +39,34 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: environmenter
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: middlewear
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.1'
42
70
  - !ruby/object:Gem::Dependency
43
71
  name: mixlib-cli
44
72
  requirement: !ruby/object:Gem::Requirement
@@ -101,14 +129,14 @@ dependencies:
101
129
  requirements:
102
130
  - - "~>"
103
131
  - !ruby/object:Gem::Version
104
- version: 4.3.1
132
+ version: '4.3'
105
133
  type: :development
106
134
  prerelease: false
107
135
  version_requirements: !ruby/object:Gem::Requirement
108
136
  requirements:
109
137
  - - "~>"
110
138
  - !ruby/object:Gem::Version
111
- version: 4.3.1
139
+ version: '4.3'
112
140
  - !ruby/object:Gem::Dependency
113
141
  name: rake
114
142
  requirement: !ruby/object:Gem::Requirement
@@ -129,14 +157,14 @@ dependencies:
129
157
  requirements:
130
158
  - - "~>"
131
159
  - !ruby/object:Gem::Version
132
- version: 3.1.0
160
+ version: '3.1'
133
161
  type: :development
134
162
  prerelease: false
135
163
  version_requirements: !ruby/object:Gem::Requirement
136
164
  requirements:
137
165
  - - "~>"
138
166
  - !ruby/object:Gem::Version
139
- version: 3.1.0
167
+ version: '3.1'
140
168
  - !ruby/object:Gem::Dependency
141
169
  name: em-spec
142
170
  requirement: !ruby/object:Gem::Requirement
@@ -180,7 +208,6 @@ files:
180
208
  - lib/lapine/consumer/config.rb
181
209
  - lib/lapine/consumer/connection.rb
182
210
  - lib/lapine/consumer/dispatcher.rb
183
- - lib/lapine/consumer/environment.rb
184
211
  - lib/lapine/consumer/message.rb
185
212
  - lib/lapine/consumer/middleware.rb
186
213
  - lib/lapine/consumer/middleware/error_handler.rb
@@ -206,7 +233,7 @@ files:
206
233
  - spec/lib/lapine_spec.rb
207
234
  - spec/spec_helper.rb
208
235
  - spec/support/rspec_test_helper.rb
209
- homepage: https://github.com/wanelo/lapine
236
+ homepage: https://github.com/messagebus/lapine
210
237
  licenses:
211
238
  - MIT
212
239
  metadata: {}
@@ -226,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
253
  version: '0'
227
254
  requirements: []
228
255
  rubyforge_project:
229
- rubygems_version: 2.2.3
256
+ rubygems_version: 2.2.5
230
257
  signing_key:
231
258
  specification_version: 4
232
259
  summary: Talk to rabbits
@@ -1,47 +0,0 @@
1
- module Lapine
2
- module Consumer
3
- class Environment
4
- attr_reader :config
5
-
6
- def initialize(config)
7
- @config = config
8
- end
9
-
10
- def load!
11
- set_environment
12
- load_rails
13
- require_from_config
14
- end
15
-
16
- def set_environment
17
- ENV['RAILS_ENV'] ||= 'development'
18
- ENV['RACK_ENV'] ||= ENV['RAILS_ENV']
19
- end
20
-
21
- def load_rails
22
- begin
23
- require 'rails'
24
- if ::Rails.application.respond_to?(:eager_load)
25
- require File.expand_path('config/environment.rb')
26
- ::Rails.application.eager_load!
27
- else
28
- require File.expand_path('config/application.rb')
29
- ::Rails::Application.initializer "lapine.load_rails" do
30
- ::Rails.application.config.eager_load = true
31
- end
32
- require File.expand_path('config/environment.rb')
33
- end
34
- rescue LoadError
35
- end
36
- end
37
-
38
- def require_from_config
39
- if config.require
40
- config.require.each do |file|
41
- require File.expand_path(file)
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end