pub_sub_model_sync 0.2.0 → 0.2.1
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 +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -9
- data/lib/pub_sub_model_sync/publisher_concern.rb +5 -0
- data/lib/pub_sub_model_sync/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f3074098a97136efdb1698c4e0d3161e02f20d36d3ce4803608dcacdc826700
|
4
|
+
data.tar.gz: 0408d088ec5ee19373a6e49fa639830948d41387efc27a9fc904c04e2b5e11fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e80c2eda985a22d547f2cce08c97a997e8d06da9ff2324e5760832d81070526a34d31e9f6c5e5d6156932ce839bd70eb4e033d1c17a86ac9207b7ae582f9f854
|
7
|
+
data.tar.gz: 13c9e536b71740620f5aaa2a4bce195f0a10dddc5fe5e2ba36e41e48191b7a4f7dce3077a7cf76f3f8882b29054a9b5b015d9150872f641e9875bf66f0748586
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,8 @@ end
|
|
83
83
|
|
84
84
|
# Samples
|
85
85
|
User.create(name: 'test user', email: 'sample@gmail.com') # Review your App 2 to see the created user (only name will be saved)
|
86
|
+
User.new(name: 'test user').ps_perform_sync(:create) # similar to above to perform sync on demand
|
87
|
+
|
86
88
|
User.ps_class_publish({ msg: 'Hello' }, action: :greeting) # User.greeting method (Class method) will be called in App2
|
87
89
|
PubSubModelSync::Publisher.new.publish_data(User, { msg: 'Hello' }, :greeting) # similar to above when not included publisher concern
|
88
90
|
```
|
@@ -113,6 +115,33 @@ class User < ActiveRecord::Base
|
|
113
115
|
end
|
114
116
|
```
|
115
117
|
|
118
|
+
## API
|
119
|
+
- Perform sync on demand (:create, :update, :destroy):
|
120
|
+
The target model will receive a notification to perform the indicated action
|
121
|
+
```my_model.ps_perform_sync(action_name)```
|
122
|
+
|
123
|
+
- Class level notification:
|
124
|
+
```User.ps_class_publish(data, action: action_name, as_klass: custom_klass_name)```
|
125
|
+
Target class ```User.action_name``` will be called when message is received
|
126
|
+
* data: (required, :hash) message value to deliver
|
127
|
+
* action_name: (required, :sim) same action name as defined in ps_class_subscribe(...)
|
128
|
+
* as_klass: (optional, :string) same class name as defined in ps_class_subscribe(...)
|
129
|
+
|
130
|
+
- Class level notification (Same as above: on demand call)
|
131
|
+
```PubSubModelSync::Publisher.new.publish_data(Klass_name, data, action_name)```
|
132
|
+
* klass_name: (required, Class) same class name as defined in ps_class_subscribe(...)
|
133
|
+
* data: (required, :hash) message value to deliver
|
134
|
+
* action_name: (required, :sim) same action name as defined in ps_class_subscribe(...)
|
135
|
+
|
136
|
+
- Get crud subscription configured for the class
|
137
|
+
```User.ps_subscriber(action_name)```
|
138
|
+
* action_name (default :create, :sym): can be :create, :update, :destroy
|
139
|
+
- Get crud publisher configured for the class
|
140
|
+
```User.ps_publisher(action_name)```
|
141
|
+
* action_name (default :create, :sym): can be :create, :update, :destroy
|
142
|
+
- Inspect all listeners configured for a class
|
143
|
+
```PubSubModelSync::Config.listeners```
|
144
|
+
|
116
145
|
## Testing with RSpec
|
117
146
|
- Config: (spec/rails_helper.rb)
|
118
147
|
```ruby
|
@@ -178,15 +207,6 @@ end
|
|
178
207
|
expect_any_instance_of(publisher).to receive(:publish_data).with('User', data, action)
|
179
208
|
end
|
180
209
|
```
|
181
|
-
|
182
|
-
There are two special methods to extract crud configuration settings (attrs, id, ...):
|
183
|
-
|
184
|
-
Subscribers: ```User.ps_subscriber```
|
185
|
-
|
186
|
-
Publishers: ```User.ps_publisher```
|
187
|
-
|
188
|
-
Note: Inspect all configured listeners with:
|
189
|
-
``` PubSubModelSync::Config.listeners ```
|
190
210
|
|
191
211
|
## Contributing
|
192
212
|
|
@@ -11,6 +11,11 @@ module PubSubModelSync
|
|
11
11
|
false
|
12
12
|
end
|
13
13
|
|
14
|
+
def ps_perform_sync(action = :create)
|
15
|
+
service = self.class.ps_publisher_service
|
16
|
+
service.publish_model(self, action, self.class.ps_publisher_info(action))
|
17
|
+
end
|
18
|
+
|
14
19
|
module ClassMethods
|
15
20
|
# Permit to publish crud actions (:create, :update, :destroy)
|
16
21
|
# @param settings (Hash): { actions: nil, as_klass: nil, id: nil }
|