pub_sub_model_sync 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -1
- data/lib/pub_sub_model_sync/config.rb +3 -3
- data/lib/pub_sub_model_sync/publisher.rb +4 -0
- data/lib/pub_sub_model_sync/publisher_concern.rb +4 -0
- data/lib/pub_sub_model_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba16c2e3129caa85cf184030955e6a1de130b23b9b552a620c1354234eb5376
|
4
|
+
data.tar.gz: a4b3eb7514efe123a38fb46ed933bf9ac0b1f418f1675d73b13e2cee25e6fe03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b55d2b5f1bdd763061e0c2ea60f9fe080bdb1db26e5cdb20adf33973524612d2041b0c4dab1ec1afc90e4f7a91ea8327b41ef8c9ecf53ba8bafe543b92dd74e9
|
7
|
+
data.tar.gz: 218f2d41a1fcb04d240a4c3e91daa58b989555f9a97dc488fbc0bd627c0db412e3de224afc31a02c73bfa123f8817705811da1f3e7d20d240036f00de4ccb11d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -116,6 +116,14 @@ end
|
|
116
116
|
```
|
117
117
|
|
118
118
|
## API
|
119
|
+
- To perform a callback before publishing message (CRUD)
|
120
|
+
```model.ps_before_sync(action, data_to_deliver)```
|
121
|
+
Note: If the method returns ```false```, the message will not be published
|
122
|
+
|
123
|
+
- To perform a callback after publishing message (CRUD)
|
124
|
+
```model.ps_after_sync(action, data_to_deliver)```
|
125
|
+
Note: If the method returns ```false```, the message will not be published
|
126
|
+
|
119
127
|
- Perform sync on demand (:create, :update, :destroy):
|
120
128
|
The target model will receive a notification to perform the indicated action
|
121
129
|
```my_model.ps_perform_sync(action_name)```
|
@@ -139,7 +147,7 @@ end
|
|
139
147
|
- Get crud publisher configured for the class
|
140
148
|
```User.ps_publisher(action_name)```
|
141
149
|
* action_name (default :create, :sym): can be :create, :update, :destroy
|
142
|
-
- Inspect all
|
150
|
+
- Inspect all configured listeners
|
143
151
|
```PubSubModelSync::Config.listeners```
|
144
152
|
|
145
153
|
## Testing with RSpec
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
module PubSubModelSync
|
4
4
|
class Config
|
5
|
-
cattr_accessor
|
6
|
-
cattr_accessor
|
7
|
-
cattr_accessor
|
5
|
+
cattr_accessor(:listeners) { [] }
|
6
|
+
cattr_accessor(:publishers) { [] }
|
7
|
+
cattr_accessor(:service_name) { :google }
|
8
8
|
cattr_accessor :logger
|
9
9
|
|
10
10
|
# google service
|
@@ -18,7 +18,11 @@ module PubSubModelSync
|
|
18
18
|
attributes = build_model_attrs(model, action, settings)
|
19
19
|
data = {}
|
20
20
|
data = build_model_data(model, settings[:attrs]) if action != :destroy
|
21
|
+
res_before = model.ps_before_sync(action, data)
|
22
|
+
return if res_before == false
|
23
|
+
|
21
24
|
connector.publish(data.symbolize_keys, attributes)
|
25
|
+
model.ps_after_sync(action, data)
|
22
26
|
end
|
23
27
|
|
24
28
|
def self.build_attrs(klass, action, id = nil)
|
@@ -11,6 +11,10 @@ module PubSubModelSync
|
|
11
11
|
false
|
12
12
|
end
|
13
13
|
|
14
|
+
def ps_before_sync(_action, _data); end
|
15
|
+
|
16
|
+
def ps_after_sync(_action, _data); end
|
17
|
+
|
14
18
|
def ps_perform_sync(action = :create)
|
15
19
|
service = self.class.ps_publisher_service
|
16
20
|
service.publish_model(self, action, self.class.ps_publisher_info(action))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pub_sub_model_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|