cony 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/cony/active_record.rb +18 -5
- data/spec/cony/active_record_spec.rb +3 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# :rabbit: Cony [![Build Status](https://travis-ci.org/ninech/cony.svg)](https://travis-ci.org/ninech/cony)
|
1
|
+
# :rabbit: Cony [![Build Status](https://travis-ci.org/ninech/cony.svg)](https://travis-ci.org/ninech/cony) [![Code Climate](https://codeclimate.com/github/ninech/cony.png)](https://codeclimate.com/github/ninech/cony)
|
2
2
|
|
3
3
|
Cony sends notifications about the lifecycle of your models via AMQP.
|
4
4
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/cony/active_record.rb
CHANGED
@@ -15,20 +15,20 @@ module Cony
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def cony_send_create_notify
|
18
|
-
publish(:created)
|
18
|
+
publish(:created, cony_changes_created)
|
19
19
|
end
|
20
20
|
|
21
21
|
def cony_send_update_notify
|
22
|
-
publish(:updated)
|
22
|
+
publish(:updated, cony_changes_updated)
|
23
23
|
end
|
24
24
|
|
25
25
|
def cony_send_destroy_notify
|
26
|
-
publish(:destroyed)
|
26
|
+
publish(:destroyed, cony_changes_destroyed)
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
30
|
private
|
31
|
-
def publish(type)
|
31
|
+
def publish(type, cony_changes)
|
32
32
|
return if Cony.config.test_mode
|
33
33
|
amqp_connection.publish(
|
34
34
|
{id: self.id, changes: cony_changes, model: self.class.name, event: type},
|
@@ -39,11 +39,24 @@ module Cony
|
|
39
39
|
@amqp_connection ||= Cony::AMQPConnectionHandler.new(Cony.config.amqp)
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def mapped_changes
|
43
43
|
changes.map do |name, change|
|
44
44
|
{name => {old: change.first, new: change.last}}
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def cony_changes_created
|
49
|
+
mapped_changes
|
50
|
+
end
|
51
|
+
|
52
|
+
def cony_changes_updated
|
53
|
+
mapped_changes
|
54
|
+
end
|
55
|
+
|
56
|
+
def cony_changes_destroyed
|
57
|
+
attributes.map do |name, value|
|
58
|
+
{name => {old: value, new: nil}}
|
59
|
+
end
|
60
|
+
end
|
48
61
|
end
|
49
62
|
end
|
@@ -7,6 +7,7 @@ describe Cony::ActiveRecord do
|
|
7
7
|
let(:amqp_connection) { double('Cony::AMQPConnectionHandler') }
|
8
8
|
let(:id) { 1337 }
|
9
9
|
let(:active_record_changes) { {name: ['old', 'new']} }
|
10
|
+
let(:active_record_attributes) { {name: 'value'} }
|
10
11
|
let(:cony_changes) { [{name: {old: 'old', new: 'new'}}] }
|
11
12
|
let(:expected_payload) do
|
12
13
|
{
|
@@ -26,6 +27,7 @@ describe Cony::ActiveRecord do
|
|
26
27
|
def self.name; "Anonymaus::Klass"; end
|
27
28
|
def id; #{id}; end
|
28
29
|
def changes; #{active_record_changes}; end
|
30
|
+
def attributes; #{active_record_attributes}; end
|
29
31
|
|
30
32
|
include Cony::ActiveRecord
|
31
33
|
end
|
@@ -56,6 +58,7 @@ describe Cony::ActiveRecord do
|
|
56
58
|
|
57
59
|
describe '#cony_send_destroy_notify' do
|
58
60
|
let(:event) { :destroyed }
|
61
|
+
let(:cony_changes) { [{name: {old: 'value', new: nil}}] }
|
59
62
|
it 'uses the amqp connection to send the notify' do
|
60
63
|
amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.destroyed')
|
61
64
|
subject.cony_send_destroy_notify
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash: -
|
123
|
+
hash: -395064848044904818
|
124
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
125
|
none: false
|
126
126
|
requirements:
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
segments:
|
131
131
|
- 0
|
132
|
-
hash: -
|
132
|
+
hash: -395064848044904818
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
135
|
rubygems_version: 1.8.23
|