multiple_man 0.1.0 → 0.1.1

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: 57e599dcf8963d8967ae8baff34c30f343b32b3b
4
- data.tar.gz: d960ac0f5ce2c49b62e435e832ff14b1fe352754
3
+ metadata.gz: ec0bfec609e5e0dde5ac05f5d2e27de78a8654d0
4
+ data.tar.gz: 95de9a66641c0d9d724de0bc7ab92523b4359dc9
5
5
  SHA512:
6
- metadata.gz: a50d81bd2d7aad87ea74ccdc42e671d88b42005436fde62a6a9353df0237f1138ba8dd9308d7ed93332d2cf4504c79168af0110968693ad64016df49675cf383
7
- data.tar.gz: d5ace8d5cd8c4376112c45282c1542b85b89a676a5723ccf3fafc241c7a606d33dc79570198551aca28fb4f5d89b27d7a13e9a4b5d9ffac926a1beb6cf9d68f1
6
+ metadata.gz: 4c26b2a50cb603b1981f3e50ef3a10335447ad906794718f3b581ec5b55f129ee015f909724ebc59671268e8538b11890b43d93634d3be6a0c6acef027a67bec
7
+ data.tar.gz: 1e22f37d9e12047413de4df64f4dbcf0ff3244ef5a5456e1abb813873c9120e439d16bd32651280a78352c8aac1f0a73db91e67daf927f9b85e994407f886ef2
data/lib/multiple_man.rb CHANGED
@@ -12,4 +12,8 @@ module MultipleMan
12
12
  require 'multiple_man/connection'
13
13
  require 'multiple_man/routing_key'
14
14
  require 'multiple_man/listener'
15
+
16
+ def self.logger
17
+ MultipleMan.configuration.logger
18
+ end
15
19
  end
@@ -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.topic.publish(record_data(record), routing_key: RoutingKey.new(record, operation).to_s)
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
- @connection ||= Connection.new
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)
@@ -1,3 +1,3 @@
1
1
  module MultipleMan
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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