pubsub_tie 1.5.0 → 1.6.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/lib/pubsub_tie/events.rb +10 -0
- data/lib/pubsub_tie/publisher.rb +5 -1
- data/lib/pubsub_tie/version.rb +1 -1
- data/lib/pubsub_tie.rb +10 -2
- 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: faee4cb155d95a73de21722c7fb96a438d077c01f29ae74baee1415a4c98441a
|
|
4
|
+
data.tar.gz: 1812f9b354cd6ae24b22b61a96bfd3accd5395ef65125bcd91ed1a393322a1e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f68b6486e17275576bee73f4e7ce5dcb2571b64c4ba497ecf1dd5ecba9c6d8352030bd5933d9ddb78aec8e9023991c4145d8071d0ef332661d8da6256e0ebd0
|
|
7
|
+
data.tar.gz: f0f9018abe1e62b07489cdc3339736a6b0abf1514c7e3a89ec71cceec266c557a64e8cd6c83812203b1323208474ffd0708876e14452eeb7ac4b8c3a81c481a6
|
data/lib/pubsub_tie/events.rb
CHANGED
|
@@ -4,10 +4,20 @@ module PubSubTie
|
|
|
4
4
|
|
|
5
5
|
def configure(config)
|
|
6
6
|
@prefix = config['app_prefix']
|
|
7
|
+
common_fields = config['common'] || []
|
|
7
8
|
|
|
8
9
|
evs = config['events'].map{|e| e['name']}
|
|
9
10
|
@events = Hash[evs.map(&:to_sym).zip(config['events'])]
|
|
10
11
|
@events.each do |k, evt|
|
|
12
|
+
# Inject root-level common fields into each event's definitions
|
|
13
|
+
common_fields.each do |cf|
|
|
14
|
+
mode_key = cf['mode'] == 'REQUIRED' ? 'required' : 'optional'
|
|
15
|
+
evt[mode_key] ||= []
|
|
16
|
+
unless evt[mode_key].any? { |field| field['name'] == cf['name'] }
|
|
17
|
+
evt[mode_key] << cf
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
11
21
|
fields = (evt['required'] || []) +
|
|
12
22
|
(evt['optional'] || []) +
|
|
13
23
|
(evt['repeated'] || [])
|
data/lib/pubsub_tie/publisher.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'google/cloud/pubsub'
|
|
2
|
+
require 'securerandom'
|
|
2
3
|
|
|
3
4
|
module PubSubTie
|
|
4
5
|
module Publisher
|
|
@@ -81,8 +82,11 @@ module PubSubTie
|
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
def augmented(data, event_sym)
|
|
85
|
+
hash_data = data.to_hash.to_options
|
|
86
|
+
user_id = hash_data[:event_id]
|
|
87
|
+
event_id = (user_id && !user_id.to_s.strip.empty?) ? user_id : SecureRandom.uuid
|
|
84
88
|
{event_name: Events.name(event_sym),
|
|
85
|
-
event_time: Time.current.utc}.merge(
|
|
89
|
+
event_time: Time.current.utc}.merge(hash_data).merge(event_id: event_id)
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
def validate_types(sym, data)
|
data/lib/pubsub_tie/version.rb
CHANGED
data/lib/pubsub_tie.rb
CHANGED
|
@@ -27,15 +27,23 @@ module PubSubTie
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def configure_publisher
|
|
30
|
-
config =
|
|
30
|
+
config = load_yaml_file(File.join(app_root, 'config', 'gcp.yml'))[env]
|
|
31
31
|
Publisher.configure(config)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def configure_events
|
|
35
|
-
config =
|
|
35
|
+
config = load_yaml_file(File.join(app_root, 'config', 'events.yml'))[env]
|
|
36
36
|
Events.configure(config)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
def load_yaml_file(file_path)
|
|
40
|
+
if defined?(Psych::VERSION) && Gem::Version.new(Psych::VERSION) >= Gem::Version.new('4.0.0')
|
|
41
|
+
YAML.load_file(file_path, aliases: true)
|
|
42
|
+
else
|
|
43
|
+
YAML.load_file(file_path)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
39
47
|
def publish(topic, data, resource: nil)
|
|
40
48
|
Publisher.publish(topic, data, resource)
|
|
41
49
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pubsub_tie
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pablo Calderon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08
|
|
11
|
+
date: 2026-09-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: google-cloud-pubsub
|