pub_sub_model_sync 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6108e077451c0ffc3d3a4b277528ccf036a64edf85c84bb810bc7ce2769bdc35
4
- data.tar.gz: 63924273967917c2b5f740f0f917fa772341bc7fbd7c77b52037e9c264e5a080
3
+ metadata.gz: 6f3074098a97136efdb1698c4e0d3161e02f20d36d3ce4803608dcacdc826700
4
+ data.tar.gz: 0408d088ec5ee19373a6e49fa639830948d41387efc27a9fc904c04e2b5e11fe
5
5
  SHA512:
6
- metadata.gz: 480a5c3d69cf06837e443ed6abfef5d927ddfc3df1c48e9948487e470666cdbb11711bb73e17c85d594c29c176a3fc0108867563a14d630152f078f2034d54af
7
- data.tar.gz: 57ec430feef5ed8a5b2318703620b2d5f0d6faba14d1227f108a5411ee6fde587219e00fd3cedb8735211c9ff24dac5127af4b88428749164ce3631eb5691e45
6
+ metadata.gz: e80c2eda985a22d547f2cce08c97a997e8d06da9ff2324e5760832d81070526a34d31e9f6c5e5d6156932ce839bd70eb4e033d1c17a86ac9207b7ae582f9f854
7
+ data.tar.gz: 13c9e536b71740620f5aaa2a4bce195f0a10dddc5fe5e2ba36e41e48191b7a4f7dce3077a7cf76f3f8882b29054a9b5b015d9150872f641e9875bf66f0748586
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ # 0.2.1
4
+ - Add on demand model sync method
5
+
3
6
  # 0.2.0
4
7
  - Add apache kafka support
5
8
  - Add Service interface for future references
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pub_sub_model_sync (0.2.0)
4
+ pub_sub_model_sync (0.2.1)
5
5
  activesupport
6
6
  rails
7
7
 
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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PubSubModelSync
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pub_sub_model_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen