promiscuous 0.11.2 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/promiscuous/publisher/attributes.rb +3 -1
- data/lib/promiscuous/publisher/mongoid.rb +1 -0
- data/lib/promiscuous/publisher/mongoid/defer_embedded.rb +5 -1
- data/lib/promiscuous/publisher/mongoid/embedded_many.rb +12 -0
- data/lib/promiscuous/subscriber.rb +6 -4
- data/lib/promiscuous/subscriber/amqp.rb +1 -0
- data/lib/promiscuous/subscriber/attributes.rb +6 -10
- data/lib/promiscuous/subscriber/base.rb +4 -0
- data/lib/promiscuous/subscriber/mongoid.rb +1 -0
- data/lib/promiscuous/subscriber/mongoid/embedded.rb +4 -0
- data/lib/promiscuous/subscriber/mongoid/embedded_many.rb +44 -0
- data/lib/promiscuous/version.rb +1 -1
- metadata +20 -18
@@ -9,7 +9,9 @@ module Promiscuous::Publisher::Attributes
|
|
9
9
|
|
10
10
|
def payload_for(field)
|
11
11
|
value = instance.__send__(field)
|
12
|
-
if value.
|
12
|
+
if value.respond_to?(:promiscuous_publisher)
|
13
|
+
value.promiscuous_publisher.new(options.merge(:instance => value)).payload
|
14
|
+
elsif value.class.respond_to?(:promiscuous_publisher)
|
13
15
|
value.class.promiscuous_publisher.new(options.merge(:instance => value)).payload
|
14
16
|
else
|
15
17
|
value
|
@@ -2,6 +2,7 @@ class Promiscuous::Publisher::Mongoid < Promiscuous::Publisher::Base
|
|
2
2
|
autoload :Embedded, 'promiscuous/publisher/mongoid/embedded'
|
3
3
|
autoload :DeferEmbedded, 'promiscuous/publisher/mongoid/defer_embedded'
|
4
4
|
autoload :Defer, 'promiscuous/publisher/mongoid/defer'
|
5
|
+
autoload :EmbeddedMany, 'promiscuous/publisher/mongoid/embedded_many'
|
5
6
|
|
6
7
|
include Promiscuous::Publisher::Class
|
7
8
|
include Promiscuous::Publisher::Attributes
|
@@ -2,7 +2,11 @@ module Promiscuous::Publisher::Mongoid::DeferEmbedded
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
def payload
|
5
|
-
|
5
|
+
if instance.is_a?(Array)
|
6
|
+
Promiscuous::Publisher::Mongoid::EmbeddedMany.new(:instance => instance).payload
|
7
|
+
else
|
8
|
+
super.merge(:id => instance.id)
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
included do
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Promiscuous::Publisher::Mongoid::EmbeddedMany < Promiscuous::Publisher::Base
|
2
|
+
module Payload
|
3
|
+
def payload
|
4
|
+
instance.map { |e| e.class.promiscuous_publisher.new(:instance => e).payload }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
include Payload
|
8
|
+
|
9
|
+
include Promiscuous::Publisher::AMQP
|
10
|
+
|
11
|
+
publish :to => '__promiscuous__/embedded_many'
|
12
|
+
end
|
@@ -18,7 +18,7 @@ module Promiscuous::Subscriber
|
|
18
18
|
Lint.lint(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.
|
21
|
+
def self.subscriber_class_for(payload)
|
22
22
|
sub = AMQP.subscriber_from(payload)
|
23
23
|
if sub && defined?(Polymorphic) && sub.include?(Polymorphic)
|
24
24
|
sub = sub.polymorphic_subscriber_from(payload)
|
@@ -26,10 +26,12 @@ module Promiscuous::Subscriber
|
|
26
26
|
sub || Base
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.
|
30
|
-
|
29
|
+
def self.subscriber_for(payload, options={})
|
30
|
+
self.subscriber_class_for(payload).new(options.merge(:payload => payload))
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
+
def self.process(payload, options={})
|
34
|
+
sub = self.subscriber_for(payload, options)
|
33
35
|
sub.process
|
34
36
|
sub.instance
|
35
37
|
end
|
@@ -11,17 +11,13 @@ module Promiscuous::Subscriber::Attributes
|
|
11
11
|
raise "Attribute '#{attr}' is missing from the payload"
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
options = {}
|
15
|
+
options[:parent] = instance
|
16
|
+
options[:old_value] = instance.__send__(attr) if instance.respond_to?(attr)
|
17
|
+
sub = Promiscuous::Subscriber.subscriber_for(payload[attr], options)
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
new_value = Promiscuous::Subscriber.process(payload[attr], :old_value => old_value)
|
19
|
-
instance.__send__("#{attr}=", new_value) if old_value != new_value
|
20
|
-
else
|
21
|
-
# TODO Add unit test
|
22
|
-
new_value = Promiscuous::Subscriber.process(payload[attr])
|
23
|
-
instance.__send__("#{attr}=", new_value)
|
24
|
-
end
|
19
|
+
sub.process
|
20
|
+
instance.__send__("#{attr}=", sub.instance) if sub.should_update_parent?
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
@@ -14,6 +14,7 @@ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
|
|
14
14
|
super
|
15
15
|
|
16
16
|
if klass.embedded?
|
17
|
+
require 'promiscuous/subscriber/mongoid/embedded_many'
|
17
18
|
include Promiscuous::Subscriber::Mongoid::Embedded
|
18
19
|
else
|
19
20
|
include Promiscuous::Subscriber::Model
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Promiscuous::Subscriber::Mongoid::EmbeddedMany < Promiscuous::Subscriber::Base
|
2
|
+
include Promiscuous::Subscriber::AMQP
|
3
|
+
|
4
|
+
subscribe :from => '__promiscuous__/embedded_many'
|
5
|
+
|
6
|
+
def old_embeddeds
|
7
|
+
options[:old_value]
|
8
|
+
end
|
9
|
+
|
10
|
+
def parent
|
11
|
+
options[:parent]
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :new_embeddeds :payload
|
15
|
+
|
16
|
+
def process
|
17
|
+
# XXX Reordering is not supported
|
18
|
+
|
19
|
+
# find all updatable docs
|
20
|
+
new_embeddeds.each do |new_e|
|
21
|
+
old_e = old_embeddeds.select { |e| e.id.to_s == new_e['id'] }.first
|
22
|
+
if old_e
|
23
|
+
new_e['existed'] = true
|
24
|
+
old_e.instance_variable_set(:@keep, true)
|
25
|
+
Promiscuous::Subscriber.process(new_e, :old_value => old_e)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# delete all the old ones
|
30
|
+
old_embeddeds.each do |old_e|
|
31
|
+
old_e.destroy unless old_e.instance_variable_get(:@keep)
|
32
|
+
end
|
33
|
+
|
34
|
+
# create all the new ones
|
35
|
+
new_embeddeds.reject { |new_e| new_e['existed'] }.each do |new_e|
|
36
|
+
new_e_instance = Promiscuous::Subscriber.process(new_e)
|
37
|
+
parent.__send__(old_embeddeds.metadata[:name]) << new_e_instance
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def should_update_parent?
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
data/lib/promiscuous/version.rb
CHANGED
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.
|
4
|
+
version: 0.12.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-
|
13
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -100,69 +100,71 @@ executables: []
|
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
+
- lib/promiscuous.rb
|
104
|
+
- lib/promiscuous/amqp.rb
|
103
105
|
- lib/promiscuous/amqp/bunny.rb
|
104
106
|
- lib/promiscuous/amqp/null.rb
|
105
107
|
- lib/promiscuous/amqp/rubyamqp.rb
|
106
|
-
- lib/promiscuous/
|
108
|
+
- lib/promiscuous/common.rb
|
107
109
|
- lib/promiscuous/common/class_helpers.rb
|
108
|
-
- lib/promiscuous/common/lint/base.rb
|
109
110
|
- lib/promiscuous/common/lint.rb
|
111
|
+
- lib/promiscuous/common/lint/base.rb
|
110
112
|
- lib/promiscuous/common/options.rb
|
111
113
|
- lib/promiscuous/common/worker.rb
|
112
|
-
- lib/promiscuous/common.rb
|
113
114
|
- lib/promiscuous/config.rb
|
114
115
|
- lib/promiscuous/ephemeral.rb
|
115
116
|
- lib/promiscuous/loader.rb
|
116
117
|
- lib/promiscuous/observer.rb
|
118
|
+
- lib/promiscuous/publisher.rb
|
117
119
|
- lib/promiscuous/publisher/active_record.rb
|
118
120
|
- lib/promiscuous/publisher/amqp.rb
|
119
|
-
- lib/promiscuous/publisher/attributes.rb
|
120
121
|
- lib/promiscuous/publisher/base.rb
|
121
122
|
- lib/promiscuous/publisher/class.rb
|
122
123
|
- lib/promiscuous/publisher/envelope.rb
|
123
124
|
- lib/promiscuous/publisher/ephemeral.rb
|
124
125
|
- lib/promiscuous/publisher/error.rb
|
126
|
+
- lib/promiscuous/publisher/lint.rb
|
125
127
|
- lib/promiscuous/publisher/lint/amqp.rb
|
126
128
|
- lib/promiscuous/publisher/lint/attributes.rb
|
127
129
|
- lib/promiscuous/publisher/lint/base.rb
|
128
130
|
- lib/promiscuous/publisher/lint/class.rb
|
129
131
|
- lib/promiscuous/publisher/lint/polymorphic.rb
|
130
|
-
- lib/promiscuous/publisher/lint.rb
|
131
132
|
- lib/promiscuous/publisher/mock.rb
|
132
133
|
- lib/promiscuous/publisher/model.rb
|
134
|
+
- lib/promiscuous/publisher/mongoid/embedded.rb
|
133
135
|
- lib/promiscuous/publisher/mongoid/defer.rb
|
134
136
|
- lib/promiscuous/publisher/mongoid/defer_embedded.rb
|
135
|
-
- lib/promiscuous/publisher/mongoid/
|
136
|
-
- lib/promiscuous/publisher/mongoid.rb
|
137
|
+
- lib/promiscuous/publisher/mongoid/embedded_many.rb
|
137
138
|
- lib/promiscuous/publisher/polymorphic.rb
|
138
139
|
- lib/promiscuous/publisher/worker.rb
|
139
|
-
- lib/promiscuous/publisher.rb
|
140
|
-
- lib/promiscuous/
|
140
|
+
- lib/promiscuous/publisher/attributes.rb
|
141
|
+
- lib/promiscuous/publisher/mongoid.rb
|
141
142
|
- lib/promiscuous/railtie.rb
|
143
|
+
- lib/promiscuous/railtie/replicate.rake
|
142
144
|
- lib/promiscuous/subscriber/active_record.rb
|
143
|
-
- lib/promiscuous/subscriber/amqp.rb
|
144
|
-
- lib/promiscuous/subscriber/attributes.rb
|
145
|
-
- lib/promiscuous/subscriber/base.rb
|
146
145
|
- lib/promiscuous/subscriber/class.rb
|
147
146
|
- lib/promiscuous/subscriber/envelope.rb
|
148
147
|
- lib/promiscuous/subscriber/error.rb
|
148
|
+
- lib/promiscuous/subscriber/lint.rb
|
149
149
|
- lib/promiscuous/subscriber/lint/amqp.rb
|
150
150
|
- lib/promiscuous/subscriber/lint/attributes.rb
|
151
151
|
- lib/promiscuous/subscriber/lint/base.rb
|
152
152
|
- lib/promiscuous/subscriber/lint/class.rb
|
153
153
|
- lib/promiscuous/subscriber/lint/polymorphic.rb
|
154
|
-
- lib/promiscuous/subscriber/lint.rb
|
155
154
|
- lib/promiscuous/subscriber/model.rb
|
156
155
|
- lib/promiscuous/subscriber/mongoid/embedded.rb
|
157
|
-
- lib/promiscuous/subscriber/mongoid.rb
|
156
|
+
- lib/promiscuous/subscriber/mongoid/embedded_many.rb
|
158
157
|
- lib/promiscuous/subscriber/observer.rb
|
159
158
|
- lib/promiscuous/subscriber/polymorphic.rb
|
160
159
|
- lib/promiscuous/subscriber/upsert.rb
|
161
160
|
- lib/promiscuous/subscriber/worker.rb
|
161
|
+
- lib/promiscuous/subscriber/amqp.rb
|
162
|
+
- lib/promiscuous/subscriber/attributes.rb
|
163
|
+
- lib/promiscuous/subscriber/base.rb
|
164
|
+
- lib/promiscuous/subscriber/mongoid.rb
|
165
|
+
- lib/promiscuous/worker.rb
|
162
166
|
- lib/promiscuous/subscriber.rb
|
163
167
|
- lib/promiscuous/version.rb
|
164
|
-
- lib/promiscuous/worker.rb
|
165
|
-
- lib/promiscuous.rb
|
166
168
|
- README.md
|
167
169
|
homepage: http://github.com/crowdtap/promiscuous
|
168
170
|
licenses: []
|