promiscuous 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -69,6 +69,14 @@ Note that we use a single exchange to preserve the ordering of data updates
69
69
  across application so that subscribers always see a consistant state of the
70
70
  system.
71
71
 
72
+ Synching databases
73
+ -------------------
74
+
75
+ Documents are created if not present when receiving an update on a non existing
76
+ document.
77
+
78
+ TODO: Explain how to sync databases.
79
+
72
80
  WARNING/TODO
73
81
  ------------
74
82
 
@@ -3,21 +3,16 @@ require 'promiscuous/subscriber/custom_class'
3
3
  require 'promiscuous/subscriber/attributes'
4
4
  require 'promiscuous/subscriber/amqp'
5
5
  require 'promiscuous/subscriber/model'
6
+ require 'promiscuous/subscriber/upsert'
6
7
 
7
8
  class Promiscuous::Subscriber::ActiveRecord < Promiscuous::Subscriber::Base
8
9
  include Promiscuous::Subscriber::CustomClass
9
10
  include Promiscuous::Subscriber::Attributes
10
11
  include Promiscuous::Subscriber::AMQP
11
12
  include Promiscuous::Subscriber::Model
13
+ include Promiscuous::Subscriber::Upsert
12
14
 
13
- def self.subscribe(options)
14
- return super if options[:active_record_loaded]
15
-
16
- if options[:upsert]
17
- require 'promiscuous/subscriber/active_record/upsert'
18
- include Promiscuous::Subscriber::ActiveRecord::Upsert
19
- end
20
-
21
- self.subscribe(options.merge(:active_record_loaded => true))
15
+ def self.missing_record_exception
16
+ ActiveRecord::RecordNotFound
22
17
  end
23
18
  end
@@ -12,6 +12,10 @@ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
12
12
  include Promiscuous::Subscriber::AMQP
13
13
  include Promiscuous::Subscriber::Envelope
14
14
 
15
+ def self.missing_record_exception
16
+ Mongoid::Errors::DocumentNotFound
17
+ end
18
+
15
19
  def self.subscribe(options)
16
20
  return super if options[:mongoid_loaded]
17
21
 
@@ -25,10 +29,8 @@ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
25
29
  require 'promiscuous/subscriber/model'
26
30
  include Promiscuous::Subscriber::Model
27
31
 
28
- if options[:upsert]
29
- require 'promiscuous/subscriber/mongoid/upsert'
30
- include Promiscuous::Subscriber::Mongoid::Upsert
31
- end
32
+ require 'promiscuous/subscriber/upsert'
33
+ include Promiscuous::Subscriber::Upsert
32
34
  end
33
35
 
34
36
  self.subscribe(options.merge(:mongoid_loaded => true))
@@ -1,10 +1,10 @@
1
- module Promiscuous::Subscriber::ActiveRecord::Upsert
1
+ module Promiscuous::Subscriber::Upsert
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  def fetch
5
5
  begin
6
6
  super
7
- rescue ActiveRecord::RecordNotFound
7
+ rescue self.class.missing_record_exception
8
8
  Promiscuous.warn "[receive] upserting #{payload}"
9
9
  klass.new.tap { |o| o.id = id }
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Promiscuous
2
- VERSION = '0.6.3'
2
+ VERSION = '0.6.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promiscuous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-13 00:00:00.000000000 Z
13
+ date: 2012-08-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongoid
@@ -120,8 +120,6 @@ files:
120
120
  - lib/promiscuous/railtie.rb
121
121
  - lib/promiscuous/railtie/replicate.rake
122
122
  - lib/promiscuous/subscriber.rb
123
- - lib/promiscuous/subscriber/active_record.rb
124
- - lib/promiscuous/subscriber/active_record/upsert.rb
125
123
  - lib/promiscuous/subscriber/amqp.rb
126
124
  - lib/promiscuous/subscriber/attributes.rb
127
125
  - lib/promiscuous/subscriber/base.rb
@@ -129,12 +127,13 @@ files:
129
127
  - lib/promiscuous/subscriber/envelope.rb
130
128
  - lib/promiscuous/subscriber/error.rb
131
129
  - lib/promiscuous/subscriber/generic.rb
132
- - lib/promiscuous/subscriber/model.rb
133
- - lib/promiscuous/subscriber/mongoid.rb
134
130
  - lib/promiscuous/subscriber/mongoid/embedded.rb
135
131
  - lib/promiscuous/subscriber/mongoid/root.rb
136
- - lib/promiscuous/subscriber/mongoid/upsert.rb
137
132
  - lib/promiscuous/subscriber/polymorphic.rb
133
+ - lib/promiscuous/subscriber/model.rb
134
+ - lib/promiscuous/subscriber/active_record.rb
135
+ - lib/promiscuous/subscriber/mongoid.rb
136
+ - lib/promiscuous/subscriber/upsert.rb
138
137
  - lib/promiscuous/config.rb
139
138
  - lib/promiscuous/worker.rb
140
139
  - lib/promiscuous/version.rb
@@ -1,12 +0,0 @@
1
- module Promiscuous::Subscriber::Mongoid::Upsert
2
- extend ActiveSupport::Concern
3
-
4
- def fetch
5
- begin
6
- super
7
- rescue Mongoid::Errors::DocumentNotFound
8
- Promiscuous.warn "[receive] upserting #{payload}"
9
- klass.new.tap { |o| o.id = id }
10
- end
11
- end
12
- end