promiscuous 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  module Promiscuous::Publisher::Mongoid::Defer
2
2
  extend ActiveSupport::Concern
3
+ include Promiscuous::Publisher::Envelope
3
4
 
4
5
  mattr_accessor :klasses
5
6
  mattr_accessor :collections
@@ -10,6 +11,10 @@ module Promiscuous::Publisher::Mongoid::Defer
10
11
  super unless should_defer?
11
12
  end
12
13
 
14
+ def payload
15
+ super.merge(:version => instance._psv)
16
+ end
17
+
13
18
  def should_defer?
14
19
  if options.has_key?(:defer)
15
20
  options[:defer]
@@ -26,10 +31,11 @@ module Promiscuous::Publisher::Mongoid::Defer
26
31
  alias_method :update_orig, :update
27
32
  def update(change, flags = nil)
28
33
  if Promiscuous::Publisher::Mongoid::Defer.collections[@collection.name]
29
- psp_field = :_psp
30
34
  change = change.dup
31
35
  change['$set'] ||= {}
32
- change['$set'].merge!(psp_field => true)
36
+ change['$inc'] ||= {}
37
+ change['$set'].merge!(:_psp => true)
38
+ change['$inc'].merge!(:_psv => 1)
33
39
  end
34
40
  update_orig(change, flags)
35
41
  end
@@ -44,6 +50,7 @@ module Promiscuous::Publisher::Mongoid::Defer
44
50
 
45
51
  # TODO Make sure we are not overriding a field, although VERY unlikly
46
52
  field :_psp, :type => Boolean
53
+ field :_psv, :type => Integer
47
54
  index({:_psp => 1}, :background => true, :sparse => true)
48
55
 
49
56
  Promiscuous::Publisher::Mongoid::Defer.hook_mongoid
@@ -41,12 +41,20 @@ module Promiscuous::Subscriber::Model
41
41
  def process
42
42
  super
43
43
  case operation
44
- when :create then instance.save!
45
- when :update then instance.save!
46
- when :destroy then instance.destroy
44
+ when :create then save_instance
45
+ when :update then save_instance
46
+ when :destroy then destroy_instance
47
47
  end
48
48
  end
49
49
 
50
+ def save_instance
51
+ instance.save!
52
+ end
53
+
54
+ def destroy_instance
55
+ instance.destroy
56
+ end
57
+
50
58
  included do
51
59
  use_option :foreign_key
52
60
 
@@ -1,5 +1,6 @@
1
1
  class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
2
- autoload :Embedded, 'promiscuous/subscriber/mongoid/embedded'
2
+ autoload :Embedded, 'promiscuous/subscriber/mongoid/embedded'
3
+ autoload :Versioning, 'promiscuous/subscriber/mongoid/versioning'
3
4
 
4
5
  include Promiscuous::Subscriber::Class
5
6
  include Promiscuous::Subscriber::Attributes
@@ -19,6 +20,7 @@ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
19
20
  else
20
21
  include Promiscuous::Subscriber::Model
21
22
  include Promiscuous::Subscriber::Upsert
23
+ include Promiscuous::Subscriber::Mongoid::Versioning
22
24
  end
23
25
  end
24
26
  end
@@ -0,0 +1,36 @@
1
+ module Promiscuous::Subscriber::Mongoid::Versioning
2
+ extend ActiveSupport::Concern
3
+
4
+ module AtomicSelector
5
+ extend ActiveSupport::Concern
6
+
7
+ def atomic_selector
8
+ if use_atomic_promiscuous_selector
9
+ super.merge({ '$or' => [{'_psv' => { '$lt' => self._psv }},
10
+ {'_psv' => { '$exists' => false }}]})
11
+ else
12
+ super
13
+ end
14
+ end
15
+
16
+ included do
17
+ attr_accessor :use_atomic_promiscuous_selector
18
+ field :_psv, :type => Integer
19
+ end
20
+ end
21
+
22
+ def save_instance
23
+ if version
24
+ instance._psv = version
25
+ instance.use_atomic_promiscuous_selector = true
26
+ end
27
+ super
28
+ ensure
29
+ instance.use_atomic_promiscuous_selector = false
30
+ end
31
+
32
+ included do
33
+ klass.__send__(:include, AtomicSelector)
34
+ use_payload_attribute :version
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Promiscuous
2
- VERSION = '0.13.0'
2
+ VERSION = '0.14.0'
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.13.0
4
+ version: 0.14.0
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-11-15 00:00:00.000000000 Z
13
+ date: 2012-11-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -116,71 +116,72 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - lib/promiscuous.rb
120
- - lib/promiscuous/amqp/bunny.rb
121
119
  - lib/promiscuous/amqp/null.rb
120
+ - lib/promiscuous/amqp/bunny.rb
122
121
  - lib/promiscuous/amqp/rubyamqp.rb
123
- - lib/promiscuous/common.rb
124
- - lib/promiscuous/common/class_helpers.rb
125
122
  - lib/promiscuous/common/lint.rb
126
123
  - lib/promiscuous/common/lint/base.rb
127
124
  - lib/promiscuous/common/options.rb
125
+ - lib/promiscuous/common/class_helpers.rb
128
126
  - lib/promiscuous/common/worker.rb
129
- - lib/promiscuous/config.rb
130
127
  - lib/promiscuous/loader.rb
131
- - lib/promiscuous/observer.rb
132
- - lib/promiscuous/publisher.rb
133
128
  - lib/promiscuous/publisher/active_record.rb
134
129
  - lib/promiscuous/publisher/base.rb
135
- - lib/promiscuous/publisher/class.rb
136
130
  - lib/promiscuous/publisher/envelope.rb
137
- - lib/promiscuous/publisher/ephemeral.rb
138
- - lib/promiscuous/publisher/error.rb
139
131
  - lib/promiscuous/publisher/lint.rb
140
132
  - lib/promiscuous/publisher/lint/amqp.rb
141
133
  - lib/promiscuous/publisher/lint/attributes.rb
142
134
  - lib/promiscuous/publisher/lint/base.rb
143
135
  - lib/promiscuous/publisher/lint/class.rb
144
136
  - lib/promiscuous/publisher/lint/polymorphic.rb
145
- - lib/promiscuous/publisher/mock.rb
146
137
  - lib/promiscuous/publisher/mongoid/embedded.rb
147
- - lib/promiscuous/publisher/mongoid/defer.rb
148
138
  - lib/promiscuous/publisher/mongoid/defer_embedded.rb
149
139
  - lib/promiscuous/publisher/mongoid/embedded_many.rb
140
+ - lib/promiscuous/publisher/mongoid/defer.rb
150
141
  - lib/promiscuous/publisher/polymorphic.rb
142
+ - lib/promiscuous/publisher/class.rb
143
+ - lib/promiscuous/publisher/mock.rb
144
+ - lib/promiscuous/publisher/error.rb
145
+ - lib/promiscuous/publisher/ephemeral.rb
151
146
  - lib/promiscuous/publisher/attributes.rb
152
147
  - lib/promiscuous/publisher/mongoid.rb
153
148
  - lib/promiscuous/publisher/amqp.rb
154
- - lib/promiscuous/publisher/model.rb
155
149
  - lib/promiscuous/publisher/worker.rb
150
+ - lib/promiscuous/publisher/model.rb
156
151
  - lib/promiscuous/railtie.rb
157
152
  - lib/promiscuous/railtie/replicate.rake
158
153
  - lib/promiscuous/subscriber/active_record.rb
159
- - lib/promiscuous/subscriber/class.rb
160
154
  - lib/promiscuous/subscriber/envelope.rb
161
155
  - lib/promiscuous/subscriber/error.rb
162
156
  - lib/promiscuous/subscriber/lint.rb
163
157
  - lib/promiscuous/subscriber/lint/amqp.rb
164
- - lib/promiscuous/subscriber/lint/attributes.rb
165
158
  - lib/promiscuous/subscriber/lint/base.rb
166
159
  - lib/promiscuous/subscriber/lint/class.rb
167
160
  - lib/promiscuous/subscriber/lint/polymorphic.rb
168
- - lib/promiscuous/subscriber/model.rb
169
- - lib/promiscuous/subscriber/mongoid/embedded.rb
161
+ - lib/promiscuous/subscriber/lint/attributes.rb
170
162
  - lib/promiscuous/subscriber/mongoid/embedded_many.rb
163
+ - lib/promiscuous/subscriber/mongoid/embedded.rb
164
+ - lib/promiscuous/subscriber/mongoid/versioning.rb
165
+ - lib/promiscuous/subscriber/upsert.rb
166
+ - lib/promiscuous/subscriber/class.rb
171
167
  - lib/promiscuous/subscriber/observer.rb
172
168
  - lib/promiscuous/subscriber/polymorphic.rb
173
- - lib/promiscuous/subscriber/upsert.rb
174
169
  - lib/promiscuous/subscriber/amqp.rb
175
- - lib/promiscuous/subscriber/attributes.rb
176
170
  - lib/promiscuous/subscriber/base.rb
177
- - lib/promiscuous/subscriber/mongoid.rb
178
171
  - lib/promiscuous/subscriber/worker.rb
179
- - lib/promiscuous/subscriber.rb
180
- - lib/promiscuous/ephemeral.rb
172
+ - lib/promiscuous/subscriber/attributes.rb
173
+ - lib/promiscuous/subscriber/model.rb
174
+ - lib/promiscuous/subscriber/mongoid.rb
175
+ - lib/promiscuous/observer.rb
176
+ - lib/promiscuous/common.rb
177
+ - lib/promiscuous/publisher.rb
178
+ - lib/promiscuous/config.rb
181
179
  - lib/promiscuous/amqp.rb
182
180
  - lib/promiscuous/worker.rb
181
+ - lib/promiscuous/ephemeral.rb
182
+ - lib/promiscuous/subscriber.rb
183
183
  - lib/promiscuous/version.rb
184
+ - lib/promiscuous.rb
184
185
  - README.md
185
186
  homepage: http://github.com/crowdtap/promiscuous
186
187
  licenses: []