promiscuous 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/promiscuous/common/options.rb +44 -0
- data/lib/promiscuous/common.rb +7 -0
- data/lib/promiscuous/publisher/active_record.rb +1 -9
- data/lib/promiscuous/publisher/amqp.rb +0 -2
- data/lib/promiscuous/publisher/attributes.rb +2 -7
- data/lib/promiscuous/publisher/base.rb +4 -9
- data/lib/promiscuous/publisher/class.rb +35 -0
- data/lib/promiscuous/publisher/lint/amqp.rb +1 -1
- data/lib/promiscuous/publisher/lint/attributes.rb +1 -3
- data/lib/promiscuous/publisher/lint/class_bind.rb +1 -1
- data/lib/promiscuous/publisher/lint/polymorphic.rb +2 -2
- data/lib/promiscuous/publisher/model.rb +9 -9
- data/lib/promiscuous/publisher/mongoid.rb +3 -11
- data/lib/promiscuous/publisher/polymorphic.rb +0 -14
- data/lib/promiscuous/publisher.rb +9 -2
- data/lib/promiscuous/subscriber/active_record.rb +1 -8
- data/lib/promiscuous/subscriber/amqp.rb +0 -2
- data/lib/promiscuous/subscriber/base.rb +3 -24
- data/lib/promiscuous/subscriber/{custom_class.rb → class.rb} +2 -8
- data/lib/promiscuous/subscriber/model.rb +0 -2
- data/lib/promiscuous/subscriber/mongoid.rb +3 -13
- data/lib/promiscuous/subscriber/polymorphic.rb +0 -2
- data/lib/promiscuous/subscriber.rb +9 -1
- data/lib/promiscuous/version.rb +1 -1
- data/lib/promiscuous.rb +1 -0
- metadata +6 -5
- data/lib/promiscuous/publisher/class_bind.rb +0 -27
- data/lib/promiscuous/publisher/lint/model.rb +0 -3
@@ -0,0 +1,44 @@
|
|
1
|
+
module Promiscuous::Common::Options
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
class_attribute :options, :options_mappings,
|
6
|
+
:instance_reader => false,
|
7
|
+
:instance_writer => false
|
8
|
+
self.options = self.options_mappings = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def inherited(subclass)
|
13
|
+
super
|
14
|
+
subclass.options = self.options.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
def use_option(attr, options={})
|
18
|
+
instance_reader = options.fetch(:instance_reader, true)
|
19
|
+
attr_alias = options.fetch(:as, attr)
|
20
|
+
|
21
|
+
self.options_mappings[attr] = attr_alias
|
22
|
+
|
23
|
+
base = self.ancestors[self.ancestors.index(Promiscuous::Common::Options) - 1]
|
24
|
+
|
25
|
+
# We need to let all the modules overload these methods, which is
|
26
|
+
# why we are injecting at the base level.
|
27
|
+
base.singleton_class.class_eval do
|
28
|
+
define_method("#{attr_alias}") { self.options[attr] }
|
29
|
+
define_method("#{attr_alias}=") { |value| self.options[attr] = value }
|
30
|
+
end
|
31
|
+
|
32
|
+
if instance_reader
|
33
|
+
define_method("#{attr_alias}") { self.class.__send__("#{attr_alias}") }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_options(options)
|
38
|
+
options.each do |attr, value|
|
39
|
+
attr_alias = self.options_mappings[attr]
|
40
|
+
self.__send__("#{attr_alias}=", value) if attr_alias
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,14 +1,6 @@
|
|
1
|
-
require 'promiscuous/publisher/base'
|
2
|
-
require 'promiscuous/publisher/class_bind'
|
3
|
-
require 'promiscuous/publisher/attributes'
|
4
|
-
require 'promiscuous/publisher/amqp'
|
5
|
-
require 'promiscuous/publisher/envelope'
|
6
|
-
require 'promiscuous/publisher/model'
|
7
|
-
|
8
1
|
class Promiscuous::Publisher::ActiveRecord < Promiscuous::Publisher::Base
|
9
|
-
include Promiscuous::Publisher::
|
2
|
+
include Promiscuous::Publisher::Class
|
10
3
|
include Promiscuous::Publisher::Attributes
|
11
4
|
include Promiscuous::Publisher::AMQP
|
12
|
-
include Promiscuous::Publisher::Envelope
|
13
5
|
include Promiscuous::Publisher::Model
|
14
6
|
end
|
@@ -23,13 +23,8 @@ module Promiscuous::Publisher::Attributes
|
|
23
23
|
included { use_option :attributes }
|
24
24
|
|
25
25
|
module ClassMethods
|
26
|
-
def
|
27
|
-
|
28
|
-
options = options.dup
|
29
|
-
options[:attributes] = (self.options[:attributes] + options[:attributes]).uniq
|
30
|
-
end
|
31
|
-
|
32
|
-
super(options)
|
26
|
+
def attributes=(value)
|
27
|
+
super(superclass.attributes.to_a + value)
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Promiscuous::Publisher::Base
|
2
|
+
include Promiscuous::Common::Options
|
3
|
+
|
4
|
+
cattr_accessor :published
|
2
5
|
attr_accessor :options
|
3
|
-
class_attribute :options, :published
|
4
|
-
self.options = {}
|
5
6
|
|
6
7
|
def initialize(options)
|
7
8
|
self.options = options
|
@@ -12,13 +13,7 @@ class Promiscuous::Publisher::Base
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.publish(options)
|
15
|
-
|
16
|
+
load_options(options)
|
16
17
|
self.published = true
|
17
18
|
end
|
18
|
-
|
19
|
-
def self.use_option(attr)
|
20
|
-
define_method(attr) do
|
21
|
-
self.class.options[attr]
|
22
|
-
end
|
23
|
-
end
|
24
19
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Promiscuous::Publisher::Class
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included { use_option :class, :as => :klass }
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def setup_binding
|
8
|
+
publisher_class = self
|
9
|
+
klass.class_eval do
|
10
|
+
class_attribute :promiscuous_publisher
|
11
|
+
self.promiscuous_publisher = publisher_class
|
12
|
+
end if klass
|
13
|
+
end
|
14
|
+
|
15
|
+
def inherited(subclass)
|
16
|
+
super
|
17
|
+
subclass.setup_binding unless options[:class]
|
18
|
+
end
|
19
|
+
|
20
|
+
def klass=(value)
|
21
|
+
super
|
22
|
+
setup_binding
|
23
|
+
end
|
24
|
+
|
25
|
+
def klass
|
26
|
+
if super
|
27
|
+
"::#{super}".constantize
|
28
|
+
elsif name
|
29
|
+
class_name = "::#{name.split('::').last}"
|
30
|
+
class_name = $1 if class_name =~ /^(.+)Publisher$/
|
31
|
+
class_name.constantize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -5,10 +5,8 @@ module Promiscuous::Publisher::Lint::Attributes
|
|
5
5
|
super
|
6
6
|
|
7
7
|
instance = klass.new
|
8
|
-
publisher.
|
8
|
+
publisher.attributes.each do |attr|
|
9
9
|
instance.respond_to?(attr) or instance.__send__(attr)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
included { use_option(:klass) }
|
14
12
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'promiscuous/publisher/envelope'
|
2
|
-
|
3
1
|
module Promiscuous::Publisher::Model
|
4
2
|
extend ActiveSupport::Concern
|
5
3
|
include Promiscuous::Publisher::Envelope
|
@@ -27,13 +25,15 @@ module Promiscuous::Publisher::Model
|
|
27
25
|
end
|
28
26
|
|
29
27
|
def hook_callbacks
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
klass.class_eval do
|
29
|
+
cattr_accessor :publisher_operation_hooked
|
30
|
+
return if self.publisher_operation_hooked
|
31
|
+
self.publisher_operation_hooked = true
|
32
|
+
|
33
|
+
[:create, :update, :destroy].each do |operation|
|
34
|
+
__send__("after_#{operation}", "promiscuous_publish_#{operation}".to_sym)
|
35
|
+
define_method "promiscuous_publish_#{operation}" do
|
36
|
+
self.class.promiscuous_publisher.new(:instance => self, :operation => operation).amqp_publish
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,25 +1,17 @@
|
|
1
|
-
require 'promiscuous/publisher/base'
|
2
|
-
require 'promiscuous/publisher/class_bind'
|
3
|
-
require 'promiscuous/publisher/attributes'
|
4
|
-
require 'promiscuous/publisher/polymorphic'
|
5
|
-
require 'promiscuous/publisher/amqp'
|
6
|
-
require 'promiscuous/publisher/envelope'
|
7
|
-
|
8
1
|
class Promiscuous::Publisher::Mongoid < Promiscuous::Publisher::Base
|
9
|
-
|
2
|
+
autoload :Embedded, 'promiscuous/publisher/mongoid/embedded'
|
3
|
+
|
4
|
+
include Promiscuous::Publisher::Class
|
10
5
|
include Promiscuous::Publisher::Attributes
|
11
6
|
include Promiscuous::Publisher::Polymorphic
|
12
7
|
include Promiscuous::Publisher::AMQP
|
13
|
-
include Promiscuous::Publisher::Envelope
|
14
8
|
|
15
9
|
def self.publish(options)
|
16
10
|
super
|
17
11
|
|
18
12
|
if klass.embedded?
|
19
|
-
require 'promiscuous/publisher/mongoid/embedded'
|
20
13
|
include Promiscuous::Publisher::Mongoid::Embedded
|
21
14
|
else
|
22
|
-
require 'promiscuous/publisher/model'
|
23
15
|
include Promiscuous::Publisher::Model
|
24
16
|
end
|
25
17
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'promiscuous/publisher/envelope'
|
2
|
-
|
3
1
|
module Promiscuous::Publisher::Polymorphic
|
4
2
|
extend ActiveSupport::Concern
|
5
3
|
include Promiscuous::Publisher::Envelope
|
@@ -7,16 +5,4 @@ module Promiscuous::Publisher::Polymorphic
|
|
7
5
|
def payload
|
8
6
|
super.merge(:type => instance.class.to_s)
|
9
7
|
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
def publish(options)
|
13
|
-
super
|
14
|
-
self.descendants.each { |subclass| inherited(subclass) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def inherited(subclass)
|
18
|
-
super
|
19
|
-
subclass.publish(options.merge(:inherited => true)) if published
|
20
|
-
end
|
21
|
-
end
|
22
8
|
end
|
@@ -1,8 +1,15 @@
|
|
1
1
|
module Promiscuous::Publisher
|
2
2
|
autoload :ActiveRecord, 'promiscuous/publisher/active_record'
|
3
|
-
autoload :
|
4
|
-
autoload :
|
3
|
+
autoload :AMQP, 'promiscuous/publisher/amqp'
|
4
|
+
autoload :Attributes, 'promiscuous/publisher/attributes'
|
5
|
+
autoload :Base, 'promiscuous/publisher/base'
|
6
|
+
autoload :Class, 'promiscuous/publisher/class'
|
7
|
+
autoload :Envelope, 'promiscuous/publisher/envelope'
|
5
8
|
autoload :Lint, 'promiscuous/publisher/lint'
|
9
|
+
autoload :Mock, 'promiscuous/publisher/mock'
|
10
|
+
autoload :Model, 'promiscuous/publisher/model'
|
11
|
+
autoload :Mongoid, 'promiscuous/publisher/mongoid'
|
12
|
+
autoload :Polymorphic, 'promiscuous/publisher/polymorphic'
|
6
13
|
|
7
14
|
def self.lint(*args)
|
8
15
|
Lint.lint(*args)
|
@@ -1,12 +1,5 @@
|
|
1
|
-
require 'promiscuous/subscriber/base'
|
2
|
-
require 'promiscuous/subscriber/custom_class'
|
3
|
-
require 'promiscuous/subscriber/attributes'
|
4
|
-
require 'promiscuous/subscriber/amqp'
|
5
|
-
require 'promiscuous/subscriber/model'
|
6
|
-
require 'promiscuous/subscriber/upsert'
|
7
|
-
|
8
1
|
class Promiscuous::Subscriber::ActiveRecord < Promiscuous::Subscriber::Base
|
9
|
-
include Promiscuous::Subscriber::
|
2
|
+
include Promiscuous::Subscriber::Class
|
10
3
|
include Promiscuous::Subscriber::Attributes
|
11
4
|
include Promiscuous::Subscriber::AMQP
|
12
5
|
include Promiscuous::Subscriber::Model
|
@@ -1,8 +1,7 @@
|
|
1
1
|
class Promiscuous::Subscriber::Base
|
2
|
-
|
3
|
-
class_attribute :options, :options_mappings, :instance_reader => false, :instance_writer => false
|
2
|
+
include Promiscuous::Common::Options
|
4
3
|
|
5
|
-
|
4
|
+
attr_accessor :options
|
6
5
|
|
7
6
|
def initialize(options)
|
8
7
|
self.options = options
|
@@ -21,26 +20,6 @@ class Promiscuous::Subscriber::Base
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.subscribe(options)
|
24
|
-
options
|
25
|
-
attr_alias = self.options_mappings[attr]
|
26
|
-
self.__send__("#{attr_alias}=", value) if attr_alias
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.inherited(subclass)
|
31
|
-
super
|
32
|
-
subclass.options = self.options.dup
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.use_option(attr, options={})
|
36
|
-
attr_alias = options[:as].nil? ? attr : options[:as]
|
37
|
-
self.options_mappings[attr] = attr_alias
|
38
|
-
|
39
|
-
# We need to let all the modules overload these methods, which is
|
40
|
-
# why we are injecting at the base level.
|
41
|
-
Promiscuous::Subscriber::Base.singleton_class.class_eval do
|
42
|
-
define_method("#{attr_alias}") { self.options[attr] }
|
43
|
-
define_method("#{attr_alias}=") { |value| self.options[attr] = value }
|
44
|
-
end
|
23
|
+
load_options(options)
|
45
24
|
end
|
46
25
|
end
|
@@ -1,12 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Promiscuous::Subscriber::CustomClass
|
1
|
+
module Promiscuous::Subscriber::Class
|
4
2
|
extend ActiveSupport::Concern
|
5
3
|
|
6
|
-
def klass
|
7
|
-
self.class.klass
|
8
|
-
end
|
9
|
-
|
10
4
|
def instance
|
11
5
|
@instance ||= fetch
|
12
6
|
end
|
@@ -17,7 +11,7 @@ module Promiscuous::Subscriber::CustomClass
|
|
17
11
|
def klass
|
18
12
|
if super
|
19
13
|
"::#{super}".constantize
|
20
|
-
|
14
|
+
elsif name
|
21
15
|
class_name = "::#{name.split('::').last}"
|
22
16
|
class_name = $1 if class_name =~ /^(.+)Subscriber$/
|
23
17
|
class_name.constantize
|
@@ -1,16 +1,10 @@
|
|
1
|
-
require 'promiscuous/subscriber/base'
|
2
|
-
require 'promiscuous/subscriber/custom_class'
|
3
|
-
require 'promiscuous/subscriber/attributes'
|
4
|
-
require 'promiscuous/subscriber/polymorphic'
|
5
|
-
require 'promiscuous/subscriber/amqp'
|
6
|
-
require 'promiscuous/subscriber/envelope'
|
7
|
-
|
8
1
|
class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
|
9
|
-
|
2
|
+
autoload :Embedded, 'promiscuous/subscriber/mongoid/embedded'
|
3
|
+
|
4
|
+
include Promiscuous::Subscriber::Class
|
10
5
|
include Promiscuous::Subscriber::Attributes
|
11
6
|
include Promiscuous::Subscriber::Polymorphic
|
12
7
|
include Promiscuous::Subscriber::AMQP
|
13
|
-
include Promiscuous::Subscriber::Envelope
|
14
8
|
|
15
9
|
def self.missing_record_exception
|
16
10
|
Mongoid::Errors::DocumentNotFound
|
@@ -20,13 +14,9 @@ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
|
|
20
14
|
super
|
21
15
|
|
22
16
|
if klass.embedded?
|
23
|
-
require 'promiscuous/subscriber/mongoid/embedded'
|
24
17
|
include Promiscuous::Subscriber::Mongoid::Embedded
|
25
18
|
else
|
26
|
-
require 'promiscuous/subscriber/model'
|
27
19
|
include Promiscuous::Subscriber::Model
|
28
|
-
|
29
|
-
require 'promiscuous/subscriber/upsert'
|
30
20
|
include Promiscuous::Subscriber::Upsert
|
31
21
|
end
|
32
22
|
end
|
@@ -1,7 +1,15 @@
|
|
1
1
|
module Promiscuous::Subscriber
|
2
2
|
autoload :ActiveRecord, 'promiscuous/subscriber/active_record'
|
3
|
-
autoload :
|
3
|
+
autoload :AMQP, 'promiscuous/subscriber/amqp'
|
4
|
+
autoload :Attributes, 'promiscuous/subscriber/attributes'
|
5
|
+
autoload :Base, 'promiscuous/subscriber/base'
|
6
|
+
autoload :Class, 'promiscuous/subscriber/class'
|
7
|
+
autoload :Envelope, 'promiscuous/subscriber/envelope'
|
4
8
|
autoload :Error, 'promiscuous/subscriber/error'
|
9
|
+
autoload :Model, 'promiscuous/subscriber/model'
|
10
|
+
autoload :Mongoid, 'promiscuous/subscriber/mongoid'
|
11
|
+
autoload :Polymorphic, 'promiscuous/subscriber/polymorphic'
|
12
|
+
autoload :Upsert, 'promiscuous/subscriber/upsert'
|
5
13
|
|
6
14
|
def self.get_subscriber_from(payload)
|
7
15
|
sub = AMQP.subscriber_from(payload)
|
data/lib/promiscuous/version.rb
CHANGED
data/lib/promiscuous.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.2
|
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
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongoid
|
@@ -117,13 +117,13 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- lib/promiscuous/version.rb
|
120
|
-
- lib/promiscuous/
|
120
|
+
- lib/promiscuous/common.rb
|
121
121
|
- lib/promiscuous/publisher/lint.rb
|
122
122
|
- lib/promiscuous/publisher/attributes.rb
|
123
|
+
- lib/promiscuous/publisher/class.rb
|
123
124
|
- lib/promiscuous/publisher/mongoid.rb
|
124
125
|
- lib/promiscuous/publisher/lint/class_bind.rb
|
125
126
|
- lib/promiscuous/publisher/lint/attributes.rb
|
126
|
-
- lib/promiscuous/publisher/lint/model.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
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/promiscuous/amqp/bunny.rb
|
141
141
|
- lib/promiscuous/publisher.rb
|
142
142
|
- lib/promiscuous/subscriber/attributes.rb
|
143
|
+
- lib/promiscuous/subscriber/class.rb
|
143
144
|
- lib/promiscuous/subscriber/mongoid.rb
|
144
145
|
- lib/promiscuous/subscriber/error.rb
|
145
146
|
- lib/promiscuous/subscriber/mongoid/embedded.rb
|
@@ -148,9 +149,9 @@ files:
|
|
148
149
|
- lib/promiscuous/subscriber/model.rb
|
149
150
|
- lib/promiscuous/subscriber/envelope.rb
|
150
151
|
- lib/promiscuous/subscriber/amqp.rb
|
151
|
-
- lib/promiscuous/subscriber/custom_class.rb
|
152
152
|
- lib/promiscuous/subscriber/base.rb
|
153
153
|
- lib/promiscuous/subscriber/polymorphic.rb
|
154
|
+
- lib/promiscuous/common/options.rb
|
154
155
|
- lib/promiscuous/worker.rb
|
155
156
|
- lib/promiscuous/railtie/replicate.rake
|
156
157
|
- lib/promiscuous/railtie.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Promiscuous::Publisher::ClassBind
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
module ClassMethods
|
5
|
-
def publish(options)
|
6
|
-
super
|
7
|
-
|
8
|
-
unless options[:inherited] and options[:class]
|
9
|
-
publisher_class = self
|
10
|
-
klass.class_eval do
|
11
|
-
class_attribute :promiscuous_publisher
|
12
|
-
self.promiscuous_publisher = publisher_class
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def klass
|
18
|
-
if options[:class]
|
19
|
-
"::#{options[:class]}".constantize
|
20
|
-
else
|
21
|
-
class_name = "::#{name.split('::').last}"
|
22
|
-
class_name = $1 if class_name =~ /^(.+)Publisher$/
|
23
|
-
class_name.constantize
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|