promiscuous 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/promiscuous/common/lint/base.rb +22 -0
- data/lib/promiscuous/common/lint.rb +3 -0
- data/lib/promiscuous/common.rb +1 -4
- data/lib/promiscuous/publisher/lint/amqp.rb +1 -1
- data/lib/promiscuous/publisher/lint/base.rb +1 -18
- data/lib/promiscuous/publisher/lint/{class_bind.rb → class.rb} +1 -2
- data/lib/promiscuous/publisher/lint.rb +3 -3
- data/lib/promiscuous/publisher/mock.rb +9 -2
- data/lib/promiscuous/subscriber/lint/amqp.rb +21 -0
- data/lib/promiscuous/subscriber/lint/attributes.rb +19 -0
- data/lib/promiscuous/subscriber/lint/base.rb +8 -0
- data/lib/promiscuous/subscriber/lint/class.rb +13 -0
- data/lib/promiscuous/subscriber/lint/polymorphic.rb +41 -0
- data/lib/promiscuous/subscriber/lint.rb +22 -0
- data/lib/promiscuous/subscriber.rb +5 -0
- data/lib/promiscuous/version.rb +1 -1
- metadata +10 -2
@@ -0,0 +1,22 @@
|
|
1
|
+
module Promiscuous::Common::Lint::Base
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
attr_accessor :options
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
self.options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def lint
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def use_option(attr)
|
17
|
+
define_method(attr) do
|
18
|
+
self.options[attr]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/promiscuous/common.rb
CHANGED
@@ -1,22 +1,5 @@
|
|
1
1
|
class Promiscuous::Publisher::Lint::Base
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(options)
|
5
|
-
self.options = options
|
6
|
-
end
|
7
|
-
|
8
|
-
def publisher_instance
|
9
|
-
@publisher_instance ||= publisher.new({})
|
10
|
-
end
|
11
|
-
|
12
|
-
def lint
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.use_option(attr)
|
16
|
-
define_method(attr) do
|
17
|
-
self.options[attr]
|
18
|
-
end
|
19
|
-
end
|
2
|
+
include Promiscuous::Common::Lint::Base
|
20
3
|
|
21
4
|
use_option(:publisher)
|
22
5
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Promiscuous::Publisher::Lint
|
2
2
|
autoload :Base, 'promiscuous/publisher/lint/base'
|
3
|
-
autoload :
|
3
|
+
autoload :Class, 'promiscuous/publisher/lint/class'
|
4
4
|
autoload :Attributes, 'promiscuous/publisher/lint/attributes'
|
5
5
|
autoload :Polymorphic, 'promiscuous/publisher/lint/polymorphic'
|
6
6
|
autoload :AMQP, 'promiscuous/publisher/lint/amqp'
|
@@ -17,8 +17,8 @@ module Promiscuous::Publisher::Lint
|
|
17
17
|
classes.each do |klass, to|
|
18
18
|
pub = get_publisher(klass)
|
19
19
|
|
20
|
-
lint = Class.new(Base)
|
21
|
-
lint.__send__(:include,
|
20
|
+
lint = ::Class.new(Base)
|
21
|
+
lint.__send__(:include, Class) if pub.include?(Promiscuous::Publisher::Class)
|
22
22
|
lint.__send__(:include, Attributes) if pub.include?(Promiscuous::Publisher::Attributes)
|
23
23
|
lint.__send__(:include, Polymorphic) if pub.include?(Promiscuous::Publisher::Polymorphic)
|
24
24
|
lint.__send__(:include, AMQP) if pub.include?(Promiscuous::Publisher::AMQP)
|
@@ -6,9 +6,10 @@ class Promiscuous::Publisher::Mock
|
|
6
6
|
self.attributes = self.attributes + options[:attributes]
|
7
7
|
end
|
8
8
|
else
|
9
|
-
class_attribute :attributes, :
|
9
|
+
class_attribute :to, :attributes, :klass
|
10
10
|
|
11
11
|
self.to = options[:to]
|
12
|
+
self.klass = options[:class]
|
12
13
|
self.attributes = options[:attributes].to_a
|
13
14
|
|
14
15
|
attr_accessor :id, :new_record
|
@@ -17,7 +18,13 @@ class Promiscuous::Publisher::Mock
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.class_name
|
20
|
-
|
21
|
+
if self.klass
|
22
|
+
self.klass
|
23
|
+
elsif name
|
24
|
+
class_name = "#{name.split('::').last}"
|
25
|
+
class_name = $1 if class_name =~ /^(.+)Publisher$/
|
26
|
+
class_name
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
def initialize
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Promiscuous::Subscriber::Lint::AMQP
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def publisher
|
5
|
+
Promiscuous::Publisher::Mock.descendants.
|
6
|
+
select { |pub| pub.superclass == Promiscuous::Publisher::Mock }.
|
7
|
+
select { |pub| pub.to == from }.
|
8
|
+
tap { |pubs| raise "#{from} has multiple publishers: #{pubs}" if pubs.size > 1 }.
|
9
|
+
first
|
10
|
+
end
|
11
|
+
|
12
|
+
def lint
|
13
|
+
super
|
14
|
+
|
15
|
+
if check_publisher
|
16
|
+
raise "No publisher found for #{publisher}" if publisher.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
included { use_option :from }
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Promiscuous::Subscriber::Lint::Attributes
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def lint
|
5
|
+
super
|
6
|
+
|
7
|
+
instance = subscriber.klass.new
|
8
|
+
subscriber.attributes.each do |attr|
|
9
|
+
instance.respond_to?("#{attr}=") or instance.__send__("#{attr}=")
|
10
|
+
end
|
11
|
+
|
12
|
+
if check_publisher
|
13
|
+
missing_attributes = subscriber.attributes - publisher.attributes
|
14
|
+
if missing_attributes.present?
|
15
|
+
raise "#{publisher} subscribes to non published attributes: #{missing_attributes.join(", ")}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Promiscuous::Subscriber::Lint::Class
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def lint
|
5
|
+
super
|
6
|
+
|
7
|
+
if klass && subscriber.klass != klass
|
8
|
+
raise "Subscriber #{subscriber} does not replicate #{klass}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
included { use_option :klass }
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Promiscuous::Subscriber::Lint::Polymorphic
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def parent_publisher
|
5
|
+
publisher
|
6
|
+
@parent_publisher
|
7
|
+
end
|
8
|
+
|
9
|
+
def publisher
|
10
|
+
@parent_publisher = super
|
11
|
+
if @parent_publisher
|
12
|
+
([parent_publisher] + parent_publisher.descendants).
|
13
|
+
select { |pub| pub.class_name == subscriber.from_type }.
|
14
|
+
first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def lint
|
19
|
+
super
|
20
|
+
|
21
|
+
if check_publisher
|
22
|
+
subscriber_types = subscriber.descendants.map &:from_type
|
23
|
+
publisher_types = publisher.descendants.map &:class_name
|
24
|
+
missing_types = publisher_types - subscriber_types
|
25
|
+
if missing_types.present?
|
26
|
+
raise "#{publisher} misses some child types: #{missing_types.join(", ")}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
unless skip_polymorphic
|
31
|
+
subscriber.descendants.each do |pub|
|
32
|
+
self.class.new(options.merge(:publisher => pub,
|
33
|
+
:skip_polymorphic => true)).lint
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
included do
|
39
|
+
use_option :skip_polymorphic
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Promiscuous::Subscriber::Lint
|
2
|
+
autoload :Base, 'promiscuous/subscriber/lint/base'
|
3
|
+
autoload :Class, 'promiscuous/subscriber/lint/class'
|
4
|
+
autoload :Attributes, 'promiscuous/subscriber/lint/attributes'
|
5
|
+
autoload :Polymorphic, 'promiscuous/subscriber/lint/polymorphic'
|
6
|
+
autoload :AMQP, 'promiscuous/subscriber/lint/amqp'
|
7
|
+
|
8
|
+
def self.lint(binding_classes)
|
9
|
+
binding_classes.each do |from, klass|
|
10
|
+
sub = Promiscuous::Subscriber::AMQP.subscribers[from]
|
11
|
+
raise "#{from} has no subscriber" if sub.nil?
|
12
|
+
|
13
|
+
lint = ::Class.new(Base)
|
14
|
+
lint.__send__(:include, Class) if sub.include?(Promiscuous::Subscriber::Class)
|
15
|
+
lint.__send__(:include, Attributes) if sub.include?(Promiscuous::Subscriber::Attributes)
|
16
|
+
lint.__send__(:include, Polymorphic) if sub.include?(Promiscuous::Subscriber::Polymorphic)
|
17
|
+
lint.__send__(:include, AMQP) if sub.include?(Promiscuous::Subscriber::AMQP)
|
18
|
+
lint.new(:klass => klass, :subscriber => sub, :from => from).lint
|
19
|
+
end
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
@@ -6,11 +6,16 @@ module Promiscuous::Subscriber
|
|
6
6
|
autoload :Class, 'promiscuous/subscriber/class'
|
7
7
|
autoload :Envelope, 'promiscuous/subscriber/envelope'
|
8
8
|
autoload :Error, 'promiscuous/subscriber/error'
|
9
|
+
autoload :Lint, 'promiscuous/subscriber/lint'
|
9
10
|
autoload :Model, 'promiscuous/subscriber/model'
|
10
11
|
autoload :Mongoid, 'promiscuous/subscriber/mongoid'
|
11
12
|
autoload :Polymorphic, 'promiscuous/subscriber/polymorphic'
|
12
13
|
autoload :Upsert, 'promiscuous/subscriber/upsert'
|
13
14
|
|
15
|
+
def self.lint(*args)
|
16
|
+
Lint.lint(*args)
|
17
|
+
end
|
18
|
+
|
14
19
|
def self.get_subscriber_from(payload)
|
15
20
|
sub = AMQP.subscriber_from(payload)
|
16
21
|
if sub && defined?(Polymorphic) && sub.include?(Polymorphic)
|
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.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -122,8 +122,8 @@ files:
|
|
122
122
|
- lib/promiscuous/publisher/attributes.rb
|
123
123
|
- lib/promiscuous/publisher/class.rb
|
124
124
|
- lib/promiscuous/publisher/mongoid.rb
|
125
|
-
- lib/promiscuous/publisher/lint/class_bind.rb
|
126
125
|
- lib/promiscuous/publisher/lint/attributes.rb
|
126
|
+
- lib/promiscuous/publisher/lint/class.rb
|
127
127
|
- lib/promiscuous/publisher/lint/amqp.rb
|
128
128
|
- lib/promiscuous/publisher/lint/base.rb
|
129
129
|
- lib/promiscuous/publisher/lint/polymorphic.rb
|
@@ -139,10 +139,16 @@ files:
|
|
139
139
|
- lib/promiscuous/amqp/rubyamqp.rb
|
140
140
|
- lib/promiscuous/amqp/bunny.rb
|
141
141
|
- lib/promiscuous/publisher.rb
|
142
|
+
- lib/promiscuous/subscriber/lint.rb
|
142
143
|
- lib/promiscuous/subscriber/attributes.rb
|
143
144
|
- lib/promiscuous/subscriber/class.rb
|
144
145
|
- lib/promiscuous/subscriber/mongoid.rb
|
145
146
|
- lib/promiscuous/subscriber/error.rb
|
147
|
+
- lib/promiscuous/subscriber/lint/attributes.rb
|
148
|
+
- lib/promiscuous/subscriber/lint/class.rb
|
149
|
+
- lib/promiscuous/subscriber/lint/amqp.rb
|
150
|
+
- lib/promiscuous/subscriber/lint/base.rb
|
151
|
+
- lib/promiscuous/subscriber/lint/polymorphic.rb
|
146
152
|
- lib/promiscuous/subscriber/mongoid/embedded.rb
|
147
153
|
- lib/promiscuous/subscriber/active_record.rb
|
148
154
|
- lib/promiscuous/subscriber/upsert.rb
|
@@ -151,7 +157,9 @@ files:
|
|
151
157
|
- lib/promiscuous/subscriber/amqp.rb
|
152
158
|
- lib/promiscuous/subscriber/base.rb
|
153
159
|
- lib/promiscuous/subscriber/polymorphic.rb
|
160
|
+
- lib/promiscuous/common/lint.rb
|
154
161
|
- lib/promiscuous/common/options.rb
|
162
|
+
- lib/promiscuous/common/lint/base.rb
|
155
163
|
- lib/promiscuous/worker.rb
|
156
164
|
- lib/promiscuous/railtie/replicate.rake
|
157
165
|
- lib/promiscuous/railtie.rb
|