multiple_man 0.1.0 → 0.1.1
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/lib/multiple_man.rb +4 -0
- data/lib/multiple_man/configuration.rb +2 -1
- data/lib/multiple_man/connection.rb +3 -0
- data/lib/multiple_man/mixins/publisher.rb +1 -0
- data/lib/multiple_man/model_publisher.rb +7 -3
- data/lib/multiple_man/version.rb +1 -1
- data/spec/logger_spec.rb +17 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec0bfec609e5e0dde5ac05f5d2e27de78a8654d0
|
4
|
+
data.tar.gz: 95de9a66641c0d9d724de0bc7ab92523b4359dc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c26b2a50cb603b1981f3e50ef3a10335447ad906794718f3b581ec5b55f129ee015f909724ebc59671268e8538b11890b43d93634d3be6a0c6acef027a67bec
|
7
|
+
data.tar.gz: 1e22f37d9e12047413de4df64f4dbcf0ff3244ef5a5456e1abb813873c9120e439d16bd32651280a78352c8aac1f0a73db91e67daf927f9b85e994407f886ef2
|
data/lib/multiple_man.rb
CHANGED
@@ -4,9 +4,10 @@ module MultipleMan
|
|
4
4
|
def initialize
|
5
5
|
self.topic_name = "multiple_man"
|
6
6
|
self.app_name = Rails.application.class.parent.to_s if defined?(Rails)
|
7
|
+
self.logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
7
8
|
end
|
8
9
|
|
9
|
-
attr_accessor :topic_name, :app_name, :connection
|
10
|
+
attr_accessor :topic_name, :app_name, :connection, :logger
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.configuration
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module MultipleMan
|
2
2
|
class Connection
|
3
3
|
def self.connect
|
4
|
+
MultipleMan.logger.info "Connecting to #{MultipleMan.configuration.connection}"
|
4
5
|
connection = Bunny.new(MultipleMan.configuration.connection)
|
6
|
+
MultipleMan.logger.info "Starting connection - block #{block_given?}"
|
5
7
|
connection.start
|
6
8
|
yield new(connection) if block_given?
|
7
9
|
ensure
|
10
|
+
MultipleMan.logger.info "Closing connection"
|
8
11
|
connection.close
|
9
12
|
end
|
10
13
|
|
@@ -6,6 +6,7 @@ module MultipleMan
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def publish(options = {})
|
9
|
+
MultipleMan.logger.info("Setting up publish for #{self.name}")
|
9
10
|
after_commit ModelPublisher.new(:create, options), on: :create
|
10
11
|
after_commit ModelPublisher.new(:update, options), on: :update
|
11
12
|
after_commit ModelPublisher.new(:destroy, options), on: :destroy
|
@@ -7,8 +7,9 @@ module MultipleMan
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def after_commit(record)
|
10
|
+
MultipleMan.logger.info("Publishing #{record}")
|
10
11
|
Connection.connect do |connection|
|
11
|
-
connection
|
12
|
+
push_record(connection, record)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -16,8 +17,11 @@ module MultipleMan
|
|
16
17
|
|
17
18
|
attr_accessor :operation, :options
|
18
19
|
|
19
|
-
def connection
|
20
|
-
|
20
|
+
def push_record(connection, record)
|
21
|
+
data = record_data(record)
|
22
|
+
routing_key = RoutingKey.new(record, operation).to_s
|
23
|
+
MultipleMan.logger.info(" Record Data: #{data} | Routing Key: #{routing_key}")
|
24
|
+
connection.topic.publish(data, routing_key: routing_key)
|
21
25
|
end
|
22
26
|
|
23
27
|
def record_data(record)
|
data/lib/multiple_man/version.rb
CHANGED
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MultipleMan do
|
4
|
+
let(:mock_logger) { double(Logger) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
MultipleMan.configure do |config|
|
8
|
+
config.logger = mock_logger
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should use the logger from configuration" do
|
13
|
+
mock_logger.should_receive(:info).with("My message")
|
14
|
+
MultipleMan.logger.info "My message"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiple_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- spec/attribute_extractor_spec.rb
|
97
97
|
- spec/connection_spec.rb
|
98
98
|
- spec/listener_spec.rb
|
99
|
+
- spec/logger_spec.rb
|
99
100
|
- spec/model_publisher_spec.rb
|
100
101
|
- spec/model_subscriber_spec.rb
|
101
102
|
- spec/publisher_spec.rb
|
@@ -130,6 +131,7 @@ test_files:
|
|
130
131
|
- spec/attribute_extractor_spec.rb
|
131
132
|
- spec/connection_spec.rb
|
132
133
|
- spec/listener_spec.rb
|
134
|
+
- spec/logger_spec.rb
|
133
135
|
- spec/model_publisher_spec.rb
|
134
136
|
- spec/model_subscriber_spec.rb
|
135
137
|
- spec/publisher_spec.rb
|