promiscuous 0.5.1 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Promiscuous
4
4
  [![Build Status](https://secure.travis-ci.org/crowdtap/promiscuous.png?branch=master)](https://secure.travis-ci.org/crowdtap/promiscuous)
5
5
 
6
6
  Promiscuous offers an automatic way of propagating your model data across one or
7
- more applications.
7
+ more applications. It supports Mongoid2, Mongoid3 and ActiveRecord.
8
8
  It uses [RabbitMQ](http://www.rabbitmq.com/).
9
9
 
10
10
  Usage
@@ -73,7 +73,8 @@ WARNING/TODO
73
73
  ------------
74
74
 
75
75
  Promiscuous does **not** handle:
76
- - Any of the atomic operatiors, such as inc, or add_to_set.
76
+ - ActiveRecord polymorphism.
77
+ - Any of the Mongoid atomic operatiors, such as inc, or add_to_set.
77
78
  - Association magic. Example:
78
79
  ```ruby
79
80
  # This will NOT replicate particiation_ids:
@@ -118,12 +119,7 @@ Compatibility
118
119
 
119
120
  Promiscuous is tested against MRI 1.9.2 and 1.9.3.
120
121
 
121
- Both Mongoid 2.4.x and Mongoid 3.0.x are supported.
122
-
123
- Acknowledgments
124
- ----------------
125
-
126
- Inspired by [Service-Oriented Design with Ruby and Rails](http://www.amazon.com/Service-Oriented-Design-Addison-Wesley-Professional-Series/dp/0321659368)
122
+ ActiveRecord, Mongoid 2.4.x and Mongoid 3.0.x are supported.
127
123
 
128
124
  License
129
125
  -------
data/lib/promiscuous.rb CHANGED
@@ -2,9 +2,16 @@ require 'active_support/core_ext'
2
2
  require 'promiscuous/config'
3
3
  require 'promiscuous/amqp'
4
4
  require 'promiscuous/loader'
5
+ require 'promiscuous/railtie' if defined?(Rails)
6
+
7
+ begin
8
+ require 'mongoid'
9
+ require 'active_record'
10
+ rescue LoadError
11
+ end
12
+
5
13
  require 'promiscuous/publisher'
6
14
  require 'promiscuous/subscriber'
7
- require 'promiscuous/railtie' if defined?(Rails)
8
15
 
9
16
  module Promiscuous
10
17
  class << self
@@ -1,3 +1,4 @@
1
1
  module Promiscuous::Publisher
2
- require 'promiscuous/publisher/mongoid'
2
+ require 'promiscuous/publisher/active_record' if defined?(ActiveRecord)
3
+ require 'promiscuous/publisher/mongoid' if defined?(Mongoid)
3
4
  end
@@ -1,14 +1,14 @@
1
- require 'promiscuous/publisher/class_bind'
2
1
  require 'promiscuous/publisher/base'
2
+ require 'promiscuous/publisher/class_bind'
3
3
  require 'promiscuous/publisher/attributes'
4
- require 'promiscuous/publisher/polymorphic'
5
4
  require 'promiscuous/publisher/amqp'
6
5
  require 'promiscuous/publisher/envelope'
6
+ require 'promiscuous/publisher/model'
7
7
 
8
- class Promiscuous::Publisher::Generic < Promiscuous::Publisher::Base
8
+ class Promiscuous::Publisher::ActiveRecord < Promiscuous::Publisher::Base
9
9
  include Promiscuous::Publisher::ClassBind
10
10
  include Promiscuous::Publisher::Attributes
11
- include Promiscuous::Publisher::Polymorphic
12
11
  include Promiscuous::Publisher::AMQP
13
12
  include Promiscuous::Publisher::Envelope
13
+ include Promiscuous::Publisher::Model
14
14
  end
@@ -1,5 +1,8 @@
1
- module Promiscuous::Publisher::Mongoid::Root
1
+ require 'promiscuous/publisher/envelope'
2
+
3
+ module Promiscuous::Publisher::Model
2
4
  extend ActiveSupport::Concern
5
+ include Promiscuous::Publisher::Envelope
3
6
 
4
7
  def operation
5
8
  options[:operation]
@@ -29,3 +32,4 @@ module Promiscuous::Publisher::Mongoid::Root
29
32
  end
30
33
  end
31
34
  end
35
+
@@ -1,6 +1,17 @@
1
- require 'promiscuous/publisher/generic'
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
+ class Promiscuous::Publisher::Mongoid < Promiscuous::Publisher::Base
9
+ include Promiscuous::Publisher::ClassBind
10
+ include Promiscuous::Publisher::Attributes
11
+ include Promiscuous::Publisher::Polymorphic
12
+ include Promiscuous::Publisher::AMQP
13
+ include Promiscuous::Publisher::Envelope
2
14
 
3
- class Promiscuous::Publisher::Mongoid < Promiscuous::Publisher::Generic
4
15
  def self.publish(options)
5
16
  return super if options[:mongoid_loaded]
6
17
 
@@ -8,8 +19,8 @@ class Promiscuous::Publisher::Mongoid < Promiscuous::Publisher::Generic
8
19
  require 'promiscuous/publisher/mongoid/embedded'
9
20
  include Promiscuous::Publisher::Mongoid::Embedded
10
21
  else
11
- require 'promiscuous/publisher/mongoid/root'
12
- include Promiscuous::Publisher::Mongoid::Root
22
+ require 'promiscuous/publisher/model'
23
+ include Promiscuous::Publisher::Model
13
24
  end
14
25
 
15
26
  self.publish(options.merge(:mongoid_loaded => true))
@@ -1,6 +1,7 @@
1
1
  module Promiscuous::Subscriber
2
+ require 'promiscuous/subscriber/active_record' if defined?(ActiveRecord)
3
+ require 'promiscuous/subscriber/mongoid' if defined?(Mongoid)
2
4
  require 'promiscuous/subscriber/error'
3
- require 'promiscuous/subscriber/mongoid'
4
5
  require 'promiscuous/subscriber/amqp'
5
6
 
6
7
  mattr_accessor :subscribers
@@ -0,0 +1,23 @@
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
+
7
+ class Promiscuous::Subscriber::ActiveRecord < Promiscuous::Subscriber::Base
8
+ include Promiscuous::Subscriber::CustomClass
9
+ include Promiscuous::Subscriber::Attributes
10
+ include Promiscuous::Subscriber::AMQP
11
+ include Promiscuous::Subscriber::Model
12
+
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))
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Promiscuous::Subscriber::ActiveRecord::Upsert
2
+ extend ActiveSupport::Concern
3
+
4
+ def fetch
5
+ begin
6
+ super
7
+ rescue ActiveRecord::RecordNotFound
8
+ Promiscuous.warn "[receive] upserting #{payload}"
9
+ klass.new.tap { |o| o.id = id }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ require 'promiscuous/subscriber/envelope'
2
+
3
+ module Promiscuous::Subscriber::Model
4
+ extend ActiveSupport::Concern
5
+ include Promiscuous::Subscriber::Envelope
6
+
7
+ def fetch
8
+ case operation
9
+ when :create
10
+ klass.new.tap { |o| o.id = id }
11
+ when :update
12
+ klass.find(id)
13
+ when :destroy
14
+ klass.find(id)
15
+ end
16
+ end
17
+
18
+ def process_attributes?
19
+ operation != :destroy
20
+ end
21
+
22
+ def process
23
+ super
24
+ case operation
25
+ when :create
26
+ instance.save!
27
+ when :update
28
+ instance.save!
29
+ when :destroy
30
+ instance.destroy
31
+ end
32
+ end
33
+
34
+ included do
35
+ use_payload_attribute :id
36
+ use_payload_attribute :operation, :symbolize => true
37
+ end
38
+ end
@@ -1,6 +1,17 @@
1
- require 'promiscuous/subscriber/generic'
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
+ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Base
9
+ include Promiscuous::Subscriber::CustomClass
10
+ include Promiscuous::Subscriber::Attributes
11
+ include Promiscuous::Subscriber::Polymorphic
12
+ include Promiscuous::Subscriber::AMQP
13
+ include Promiscuous::Subscriber::Envelope
2
14
 
3
- class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Generic
4
15
  def self.subscribe(options)
5
16
  return super if options[:mongoid_loaded]
6
17
 
@@ -11,8 +22,8 @@ class Promiscuous::Subscriber::Mongoid < Promiscuous::Subscriber::Generic
11
22
  require 'promiscuous/subscriber/mongoid/embedded'
12
23
  include Promiscuous::Subscriber::Mongoid::Embedded
13
24
  else
14
- require 'promiscuous/subscriber/mongoid/root'
15
- include Promiscuous::Subscriber::Mongoid::Root
25
+ require 'promiscuous/subscriber/model'
26
+ include Promiscuous::Subscriber::Model
16
27
 
17
28
  if options[:upsert]
18
29
  require 'promiscuous/subscriber/mongoid/upsert'
@@ -1,35 +1,6 @@
1
+ require 'promiscuous/publisher/model'
2
+
1
3
  module Promiscuous::Subscriber::Mongoid::Root
2
4
  extend ActiveSupport::Concern
3
-
4
- def fetch
5
- case operation
6
- when :create
7
- klass.new.tap { |o| o.id = id }
8
- when :update
9
- klass.find(id)
10
- when :destroy
11
- klass.find(id)
12
- end
13
- end
14
-
15
- def process_attributes?
16
- operation != :destroy
17
- end
18
-
19
- def process
20
- super
21
- case operation
22
- when :create
23
- instance.save!
24
- when :update
25
- instance.save!
26
- when :destroy
27
- instance.destroy
28
- end
29
- end
30
-
31
- included do
32
- use_payload_attribute :id
33
- use_payload_attribute :operation, :symbolize => true
34
- end
5
+ include Promiscuous::Subscriber::Model
35
6
  end
@@ -1,3 +1,3 @@
1
1
  module Promiscuous
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6'
3
3
  end
@@ -4,11 +4,13 @@ module Promiscuous
4
4
  stop = false
5
5
  lock = Mutex.new
6
6
 
7
- %w(SIGTERM SIGINT).each do |signal|
8
- Signal.trap(signal) do
9
- lock.synchronize do
10
- stop = true
11
- EM.stop
7
+ unless ENV['TEST_ENV']
8
+ %w(SIGTERM SIGINT).each do |signal|
9
+ Signal.trap(signal) do
10
+ lock.synchronize do
11
+ stop = true
12
+ EM.stop
13
+ end
12
14
  end
13
15
  end
14
16
  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.5.1
4
+ version: '0.6'
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-12 00:00:00.000000000 Z
13
+ date: 2012-08-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongoid
@@ -92,7 +92,7 @@ dependencies:
92
92
  - - ! '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
- description: Replicate data across your applications
95
+ description: Replicate your Mongoid/ActiveRecord models across your applications
96
96
  email:
97
97
  - nicolas@viennot.biz
98
98
  - kareem@doubleonemedia.com
@@ -104,9 +104,9 @@ files:
104
104
  - lib/promiscuous/publisher/class_bind.rb
105
105
  - lib/promiscuous/publisher/attributes.rb
106
106
  - lib/promiscuous/publisher/mongoid.rb
107
- - lib/promiscuous/publisher/generic.rb
108
- - lib/promiscuous/publisher/mongoid/root.rb
109
107
  - lib/promiscuous/publisher/mongoid/embedded.rb
108
+ - lib/promiscuous/publisher/active_record.rb
109
+ - lib/promiscuous/publisher/model.rb
110
110
  - lib/promiscuous/publisher/envelope.rb
111
111
  - lib/promiscuous/publisher/amqp.rb
112
112
  - lib/promiscuous/publisher/base.rb
@@ -116,12 +116,15 @@ files:
116
116
  - lib/promiscuous/amqp/bunny.rb
117
117
  - lib/promiscuous/publisher.rb
118
118
  - lib/promiscuous/subscriber/attributes.rb
119
+ - lib/promiscuous/subscriber/active_record/upsert.rb
119
120
  - lib/promiscuous/subscriber/mongoid.rb
120
121
  - lib/promiscuous/subscriber/error.rb
121
122
  - lib/promiscuous/subscriber/generic.rb
122
123
  - lib/promiscuous/subscriber/mongoid/root.rb
123
124
  - lib/promiscuous/subscriber/mongoid/embedded.rb
124
125
  - lib/promiscuous/subscriber/mongoid/upsert.rb
126
+ - lib/promiscuous/subscriber/active_record.rb
127
+ - lib/promiscuous/subscriber/model.rb
125
128
  - lib/promiscuous/subscriber/envelope.rb
126
129
  - lib/promiscuous/subscriber/amqp.rb
127
130
  - lib/promiscuous/subscriber/custom_class.rb