multiple_man 0.5.20 → 0.5.21
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 +4 -4
- data/Guardfile +38 -0
- data/README.md +4 -0
- data/lib/multiple_man/attribute_extractor.rb +9 -13
- data/lib/multiple_man/connection.rb +40 -8
- data/lib/multiple_man/version.rb +1 -1
- data/multiple_man.gemspec +2 -0
- data/spec/connection_spec.rb +1 -2
- data/spec/integration/ephermal_model_spec.rb +4 -1
- data/spec/listeners/listener_spec.rb +3 -3
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f395c0bc53fe2aab8ffde4426d0013cf9a0ee0ba
|
4
|
+
data.tar.gz: ce5554a9a4e526be5216796f0b34cecf7d7a1fa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 163c9dad1a4ee94f7e74a442721b2be649e64af233a0105d4f885695effd21c58eb4933053f5a9abdb01a1570ad1fc33ca1318c6d709753012c363c6b2843cda
|
7
|
+
data.tar.gz: 87c49def2141da2c11297facc6618c93984f31aceacbcbd40ab606ce951fcdc408d6db1e472a62fc09bcb4430dd6e954b54d46ceda053e670e69f49108381d35
|
data/Guardfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), then you will want to move
|
18
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
35
|
+
watch(%r{^spec/.+_spec\.rb$})
|
36
|
+
watch(%r{^lib/multiple_man/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
37
|
+
watch('spec/spec_helper.rb') { "spec" }
|
38
|
+
end
|
data/README.md
CHANGED
@@ -199,3 +199,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
199
199
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
200
200
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
201
201
|
THE SOFTWARE.
|
202
|
+
|
203
|
+
|
204
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
205
|
+
|
@@ -5,7 +5,7 @@ module MultipleMan
|
|
5
5
|
|
6
6
|
def initialize(record, fields, include_previous = false)
|
7
7
|
raise "Fields must be specified" unless fields
|
8
|
-
|
8
|
+
|
9
9
|
self.include_previous = include_previous
|
10
10
|
self.record = record
|
11
11
|
self.fields = fields
|
@@ -13,7 +13,7 @@ module MultipleMan
|
|
13
13
|
|
14
14
|
def as_json
|
15
15
|
if include_previous
|
16
|
-
data.merge(
|
16
|
+
data.merge({previous: data("_was")})
|
17
17
|
else
|
18
18
|
data
|
19
19
|
end
|
@@ -21,22 +21,18 @@ module MultipleMan
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def data
|
24
|
+
def data(suffix = nil)
|
25
25
|
Hash[fields.map do |field|
|
26
|
-
|
27
|
-
end]
|
26
|
+
get_field(field, suffix)
|
27
|
+
end.reject(&:nil?)]
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
[field, record.send(previous_data_method)] if record.respond_to? previous_data_method
|
34
|
-
end.reject(&:nil?)]
|
35
|
-
}
|
30
|
+
def get_field(field, suffix)
|
31
|
+
method = "#{field}#{suffix}"
|
32
|
+
[field, record.send(method)] if record.respond_to? method
|
36
33
|
end
|
37
34
|
|
38
|
-
|
39
35
|
attr_accessor :record, :fields, :identifier, :include_previous
|
40
36
|
|
41
37
|
end
|
42
|
-
end
|
38
|
+
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
require 'bunny'
|
2
|
-
require 'connection_pool'
|
3
2
|
require 'active_support/core_ext/module'
|
4
3
|
|
5
4
|
module MultipleMan
|
6
5
|
class Connection
|
6
|
+
@mutex = Mutex.new
|
7
7
|
|
8
8
|
def self.connect
|
9
|
-
connection = Bunny.new(MultipleMan.configuration.connection)
|
10
|
-
MultipleMan.logger.debug "Connecting to #{MultipleMan.configuration.connection}"
|
11
|
-
connection.start
|
12
9
|
channel = connection.create_channel
|
13
10
|
yield new(channel) if block_given?
|
11
|
+
rescue Bunny::ConnectionClosedError, Bunny::NetworkErrorWrapper
|
12
|
+
reset!
|
13
|
+
retry
|
14
14
|
ensure
|
15
15
|
channel.close if channel && channel.open?
|
16
|
-
connection.close if connection && connection.open?
|
17
16
|
end
|
18
17
|
|
19
18
|
attr_reader :topic
|
@@ -23,16 +22,49 @@ module MultipleMan
|
|
23
22
|
self.topic = channel.topic(topic_name)
|
24
23
|
end
|
25
24
|
|
25
|
+
def self.connection
|
26
|
+
@mutex.synchronize do
|
27
|
+
@connection ||= begin
|
28
|
+
connection = Bunny.new(MultipleMan.configuration.connection, heartbeat: 5)
|
29
|
+
MultipleMan.logger.debug "Connecting to #{MultipleMan.configuration.connection}"
|
30
|
+
connection.start
|
31
|
+
|
32
|
+
connection
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.reset!
|
38
|
+
@connection.close if @connection
|
39
|
+
|
40
|
+
@connection = nil
|
41
|
+
end
|
42
|
+
|
26
43
|
def topic_name
|
27
44
|
MultipleMan.configuration.topic_name
|
28
45
|
end
|
29
46
|
|
30
47
|
delegate :queue, to: :channel
|
31
|
-
|
48
|
+
|
32
49
|
private
|
33
50
|
|
34
51
|
attr_accessor :channel
|
35
52
|
attr_writer :topic
|
36
|
-
|
37
53
|
end
|
38
|
-
end
|
54
|
+
end
|
55
|
+
|
56
|
+
__END__
|
57
|
+
|
58
|
+
# Possible usage
|
59
|
+
|
60
|
+
Unicorn.after_fork do
|
61
|
+
MultipleMan::Connection.reset!
|
62
|
+
end
|
63
|
+
|
64
|
+
Sidekiq.configure_server do |config|
|
65
|
+
MultipleMan::Connection.reset!
|
66
|
+
end
|
67
|
+
|
68
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
69
|
+
MultipleMan::Connection.reset! if forked
|
70
|
+
end
|
data/lib/multiple_man/version.rb
CHANGED
data/multiple_man.gemspec
CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", '~> 10.1.0'
|
24
24
|
spec.add_development_dependency "rspec", '~> 2.14.1'
|
25
25
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
26
|
+
spec.add_development_dependency 'guard'
|
27
|
+
spec.add_development_dependency 'guard-rspec'
|
26
28
|
spec.add_runtime_dependency "bunny", '>= 1.2'
|
27
29
|
spec.add_runtime_dependency "activesupport", '>= 3.0'
|
28
30
|
spec.add_runtime_dependency "connection_pool", ">= 1.2"
|
data/spec/connection_spec.rb
CHANGED
@@ -7,8 +7,7 @@ describe MultipleMan::Connection do
|
|
7
7
|
|
8
8
|
describe "connect" do
|
9
9
|
it "should open a connection and a channel" do
|
10
|
-
|
11
|
-
Bunny.should_receive(:new).and_return(mock_bunny)
|
10
|
+
MultipleMan::Connection.should_receive(:connection).and_return(mock_bunny)
|
12
11
|
mock_bunny.should_receive(:create_channel).once.and_return(mock_channel)
|
13
12
|
|
14
13
|
described_class.connect { }
|
@@ -29,10 +29,13 @@ describe "Publishing of ephermal models" do
|
|
29
29
|
id: { id: 5 },
|
30
30
|
data: { foo: 'foo', bar: 'bar', baz: 'baz'}
|
31
31
|
}.to_json
|
32
|
+
|
33
|
+
#MultipleMan::Connection.unstub!(:connection)
|
34
|
+
|
32
35
|
expect_any_instance_of(Bunny::Exchange).to receive(:publish)
|
33
36
|
.with(payload, routing_key: 'multiple_man.Ephermal.create')
|
34
37
|
|
35
38
|
obj.multiple_man_publish(:create)
|
36
39
|
end
|
37
40
|
|
38
|
-
end
|
41
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe MultipleMan::Listeners::Listener do
|
3
|
+
describe MultipleMan::Listeners::Listener do
|
4
4
|
class MockClass1; end
|
5
5
|
class MockClass2; end
|
6
6
|
|
@@ -72,4 +72,4 @@ describe MultipleMan::Listeners::Listener do
|
|
72
72
|
|
73
73
|
listener.process_message(OpenStruct.new(routing_key: "app.MockClass1.create"), '{"a":1,"b":2}')
|
74
74
|
end
|
75
|
-
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiple_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: bunny
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +160,7 @@ files:
|
|
132
160
|
- ".gitignore"
|
133
161
|
- ".rspec"
|
134
162
|
- Gemfile
|
163
|
+
- Guardfile
|
135
164
|
- LICENSE.txt
|
136
165
|
- README.md
|
137
166
|
- Rakefile
|
@@ -193,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
222
|
version: '0'
|
194
223
|
requirements: []
|
195
224
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.
|
225
|
+
rubygems_version: 2.4.6
|
197
226
|
signing_key:
|
198
227
|
specification_version: 4
|
199
228
|
summary: MultipleMan syncs changes to ActiveRecord models via AMQP
|