zaikio-loom 0.1.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +33 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +27 -0
- data/Gemfile.lock +165 -24
- data/README.md +34 -6
- data/app/jobs/zaikio/loom/fire_event_job.rb +9 -0
- data/bin/test +5 -0
- data/config/initializers/register_zaikio_loom_event_serializer.rb +1 -0
- data/lib/zaikio/loom.rb +5 -1
- data/lib/zaikio/loom/app_configuration.rb +11 -0
- data/lib/zaikio/loom/configuration.rb +11 -15
- data/lib/zaikio/loom/engine.rb +9 -0
- data/lib/zaikio/loom/event.rb +36 -23
- data/lib/zaikio/loom/event_serializer.rb +20 -0
- data/lib/zaikio/loom/railtie.rb +6 -0
- data/lib/zaikio/loom/version.rb +1 -1
- data/zaikio-loom.gemspec +6 -0
- metadata +92 -9
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c0f9cb5244311b411a7024d1214aa0b885bb642a5b4c116aaf18e6642dc4d4
|
4
|
+
data.tar.gz: 95d524d358afba55493c097b4fe2c48096b7f089ed8f151e71592ba1b79af1e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a14d784c822c8ecb98a783aec551aa13fe2e1a59b453f249711d121935f139fda3bf5114d480ca2b8516794e63b33c7e91e3cb6450f67a9de45456029c7f5c5f
|
7
|
+
data.tar.gz: 8c8c28cc2d2a7203d21067be3b2c17fd1005492fde9ab8704d6d952bd63e2bc3d5cb908d87e884c61edd3ebf81e1d62cb0a0e6398875f13526c1b8ed7d360f49
|
@@ -0,0 +1,33 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:3.0.0
|
6
|
+
- image: circleci/redis:3.2-alpine
|
7
|
+
|
8
|
+
working_directory: ~/repo
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- checkout
|
12
|
+
|
13
|
+
- restore_cache:
|
14
|
+
keys:
|
15
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
16
|
+
# fallback to using the latest cache if no exact match is found
|
17
|
+
- v1-dependencies-
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: install dependencies
|
21
|
+
command: |
|
22
|
+
gem install bundler:2.1.4 && bundle install --jobs=4 --retry=3 --path vendor/bundle
|
23
|
+
|
24
|
+
- save_cache:
|
25
|
+
paths:
|
26
|
+
- ./vendor/bundle
|
27
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
28
|
+
|
29
|
+
# run tests!
|
30
|
+
- run:
|
31
|
+
name: run tests
|
32
|
+
command: |
|
33
|
+
bundle exec rake test
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# Zaikio Loom Ruby Gem Changelog
|
2
2
|
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 1.1.0 - 2021-01-05
|
6
|
+
|
7
|
+
- Ensure compability with Ruby 3.0 and Ruby on Rails 6.1
|
8
|
+
|
9
|
+
## 1.0.1 - 2020-06-03
|
10
|
+
|
11
|
+
- Fix a bug in the event serializer
|
12
|
+
|
13
|
+
## 1.0.0 - 2020-06-03
|
14
|
+
|
15
|
+
- Add multi client support
|
16
|
+
- Confguration format changed
|
17
|
+
|
18
|
+
## 0.3.0 - 2020-04-22
|
19
|
+
|
20
|
+
- Do not send events to Loom in development or staging environment
|
21
|
+
|
22
|
+
## 0.2.1 - 2020-03-30
|
23
|
+
|
24
|
+
- Fix bug with event serialization
|
25
|
+
|
26
|
+
## 0.2.0 - 2020-03-30
|
27
|
+
|
28
|
+
- Events are now fired in background with ActiveJob.
|
29
|
+
|
3
30
|
## 0.1.1 – 2020-01-29
|
4
31
|
|
5
32
|
- Fixes an issue with URLS build on staging and in the sandbox
|
data/Gemfile.lock
CHANGED
@@ -1,43 +1,181 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zaikio-loom (
|
4
|
+
zaikio-loom (1.1.0)
|
5
|
+
nokogiri (>= 1.11.0)
|
5
6
|
oj
|
7
|
+
rails (~> 6.0, >= 6.0.2.3)
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: https://rubygems.org/
|
9
11
|
specs:
|
12
|
+
actioncable (6.1.0)
|
13
|
+
actionpack (= 6.1.0)
|
14
|
+
activesupport (= 6.1.0)
|
15
|
+
nio4r (~> 2.0)
|
16
|
+
websocket-driver (>= 0.6.1)
|
17
|
+
actionmailbox (6.1.0)
|
18
|
+
actionpack (= 6.1.0)
|
19
|
+
activejob (= 6.1.0)
|
20
|
+
activerecord (= 6.1.0)
|
21
|
+
activestorage (= 6.1.0)
|
22
|
+
activesupport (= 6.1.0)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
actionmailer (6.1.0)
|
25
|
+
actionpack (= 6.1.0)
|
26
|
+
actionview (= 6.1.0)
|
27
|
+
activejob (= 6.1.0)
|
28
|
+
activesupport (= 6.1.0)
|
29
|
+
mail (~> 2.5, >= 2.5.4)
|
30
|
+
rails-dom-testing (~> 2.0)
|
31
|
+
actionpack (6.1.0)
|
32
|
+
actionview (= 6.1.0)
|
33
|
+
activesupport (= 6.1.0)
|
34
|
+
rack (~> 2.0, >= 2.0.9)
|
35
|
+
rack-test (>= 0.6.3)
|
36
|
+
rails-dom-testing (~> 2.0)
|
37
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
38
|
+
actiontext (6.1.0)
|
39
|
+
actionpack (= 6.1.0)
|
40
|
+
activerecord (= 6.1.0)
|
41
|
+
activestorage (= 6.1.0)
|
42
|
+
activesupport (= 6.1.0)
|
43
|
+
nokogiri (>= 1.8.5)
|
44
|
+
actionview (6.1.0)
|
45
|
+
activesupport (= 6.1.0)
|
46
|
+
builder (~> 3.1)
|
47
|
+
erubi (~> 1.4)
|
48
|
+
rails-dom-testing (~> 2.0)
|
49
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
50
|
+
activejob (6.1.0)
|
51
|
+
activesupport (= 6.1.0)
|
52
|
+
globalid (>= 0.3.6)
|
53
|
+
activemodel (6.1.0)
|
54
|
+
activesupport (= 6.1.0)
|
55
|
+
activerecord (6.1.0)
|
56
|
+
activemodel (= 6.1.0)
|
57
|
+
activesupport (= 6.1.0)
|
58
|
+
activestorage (6.1.0)
|
59
|
+
actionpack (= 6.1.0)
|
60
|
+
activejob (= 6.1.0)
|
61
|
+
activerecord (= 6.1.0)
|
62
|
+
activesupport (= 6.1.0)
|
63
|
+
marcel (~> 0.3.1)
|
64
|
+
mimemagic (~> 0.3.2)
|
65
|
+
activesupport (6.1.0)
|
66
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
67
|
+
i18n (>= 1.6, < 2)
|
68
|
+
minitest (>= 5.1)
|
69
|
+
tzinfo (~> 2.0)
|
70
|
+
zeitwerk (~> 2.3)
|
10
71
|
addressable (2.7.0)
|
11
72
|
public_suffix (>= 2.0.2, < 5.0)
|
12
|
-
ast (2.4.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
73
|
+
ast (2.4.1)
|
74
|
+
builder (3.2.4)
|
75
|
+
concurrent-ruby (1.1.7)
|
76
|
+
crack (0.4.5)
|
77
|
+
rexml
|
78
|
+
crass (1.0.6)
|
79
|
+
erubi (1.10.0)
|
80
|
+
globalid (0.4.2)
|
81
|
+
activesupport (>= 4.2.0)
|
82
|
+
hashdiff (1.0.1)
|
83
|
+
i18n (1.8.7)
|
84
|
+
concurrent-ruby (~> 1.0)
|
85
|
+
loofah (2.8.0)
|
86
|
+
crass (~> 1.0.2)
|
87
|
+
nokogiri (>= 1.5.9)
|
88
|
+
mail (2.7.1)
|
89
|
+
mini_mime (>= 0.1.1)
|
90
|
+
marcel (0.3.3)
|
91
|
+
mimemagic (~> 0.3.2)
|
92
|
+
method_source (1.0.0)
|
93
|
+
mimemagic (0.3.5)
|
94
|
+
mini_mime (1.0.2)
|
95
|
+
mini_portile2 (2.5.0)
|
96
|
+
minitest (5.14.2)
|
97
|
+
mocha (1.12.0)
|
98
|
+
nio4r (2.5.4)
|
99
|
+
nokogiri (1.11.0)
|
100
|
+
mini_portile2 (~> 2.5.0)
|
101
|
+
racc (~> 1.4)
|
102
|
+
oj (3.10.18)
|
103
|
+
parallel (1.20.1)
|
104
|
+
parser (3.0.0.0)
|
105
|
+
ast (~> 2.4.1)
|
106
|
+
public_suffix (4.0.6)
|
107
|
+
racc (1.5.2)
|
108
|
+
rack (2.2.3)
|
109
|
+
rack-test (1.1.0)
|
110
|
+
rack (>= 1.0, < 3)
|
111
|
+
rails (6.1.0)
|
112
|
+
actioncable (= 6.1.0)
|
113
|
+
actionmailbox (= 6.1.0)
|
114
|
+
actionmailer (= 6.1.0)
|
115
|
+
actionpack (= 6.1.0)
|
116
|
+
actiontext (= 6.1.0)
|
117
|
+
actionview (= 6.1.0)
|
118
|
+
activejob (= 6.1.0)
|
119
|
+
activemodel (= 6.1.0)
|
120
|
+
activerecord (= 6.1.0)
|
121
|
+
activestorage (= 6.1.0)
|
122
|
+
activesupport (= 6.1.0)
|
123
|
+
bundler (>= 1.15.0)
|
124
|
+
railties (= 6.1.0)
|
125
|
+
sprockets-rails (>= 2.0.0)
|
126
|
+
rails-dom-testing (2.0.3)
|
127
|
+
activesupport (>= 4.2.0)
|
128
|
+
nokogiri (>= 1.6)
|
129
|
+
rails-html-sanitizer (1.3.0)
|
130
|
+
loofah (~> 2.3)
|
131
|
+
railties (6.1.0)
|
132
|
+
actionpack (= 6.1.0)
|
133
|
+
activesupport (= 6.1.0)
|
134
|
+
method_source
|
135
|
+
rake (>= 0.8.7)
|
136
|
+
thor (~> 1.0)
|
23
137
|
rainbow (3.0.0)
|
24
|
-
rake (13.0.
|
25
|
-
|
26
|
-
|
138
|
+
rake (13.0.3)
|
139
|
+
regexp_parser (2.0.3)
|
140
|
+
rexml (3.2.4)
|
141
|
+
rubocop (1.7.0)
|
27
142
|
parallel (~> 1.10)
|
28
|
-
parser (>= 2.7.
|
143
|
+
parser (>= 2.7.1.5)
|
29
144
|
rainbow (>= 2.2.2, < 4.0)
|
145
|
+
regexp_parser (>= 1.8, < 3.0)
|
146
|
+
rexml
|
147
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
30
148
|
ruby-progressbar (~> 1.7)
|
31
|
-
unicode-display_width (>= 1.4.0, <
|
32
|
-
rubocop-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
149
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
150
|
+
rubocop-ast (1.4.0)
|
151
|
+
parser (>= 2.7.1.5)
|
152
|
+
rubocop-minitest (0.10.2)
|
153
|
+
rubocop (>= 0.87, < 2.0)
|
154
|
+
rubocop-performance (1.9.2)
|
155
|
+
rubocop (>= 0.90.0, < 2.0)
|
156
|
+
rubocop-ast (>= 0.4.0)
|
157
|
+
rubocop-rake (0.5.1)
|
158
|
+
rubocop
|
159
|
+
ruby-progressbar (1.11.0)
|
160
|
+
sprockets (4.0.2)
|
161
|
+
concurrent-ruby (~> 1.0)
|
162
|
+
rack (> 1, < 3)
|
163
|
+
sprockets-rails (3.2.2)
|
164
|
+
actionpack (>= 4.0)
|
165
|
+
activesupport (>= 4.0)
|
166
|
+
sprockets (>= 3.0.0)
|
167
|
+
thor (1.0.1)
|
168
|
+
tzinfo (2.0.4)
|
169
|
+
concurrent-ruby (~> 1.0)
|
170
|
+
unicode-display_width (1.7.0)
|
171
|
+
webmock (3.11.0)
|
38
172
|
addressable (>= 2.3.6)
|
39
173
|
crack (>= 0.3.2)
|
40
174
|
hashdiff (>= 0.4.0, < 2.0.0)
|
175
|
+
websocket-driver (0.7.3)
|
176
|
+
websocket-extensions (>= 0.1.0)
|
177
|
+
websocket-extensions (0.1.5)
|
178
|
+
zeitwerk (2.4.2)
|
41
179
|
|
42
180
|
PLATFORMS
|
43
181
|
ruby
|
@@ -45,11 +183,14 @@ PLATFORMS
|
|
45
183
|
DEPENDENCIES
|
46
184
|
bundler
|
47
185
|
minitest
|
186
|
+
mocha
|
48
187
|
rake
|
49
188
|
rubocop
|
189
|
+
rubocop-minitest
|
50
190
|
rubocop-performance
|
191
|
+
rubocop-rake
|
51
192
|
webmock
|
52
193
|
zaikio-loom!
|
53
194
|
|
54
195
|
BUNDLED WITH
|
55
|
-
2.
|
196
|
+
2.2.3
|
data/README.md
CHANGED
@@ -35,17 +35,35 @@ Zaikio::Loom.configure do |config|
|
|
35
35
|
|
36
36
|
# The name of your application like it is named in the directory of the
|
37
37
|
# choosen enviroment.
|
38
|
-
config.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
config.application 'my_application' do |app|
|
39
|
+
# Your application's event password for the choosen environment
|
40
|
+
# Do not add this password into version control.
|
41
|
+
app.password = ENV.fetch('ZAIKIO_LOOM_PASSWORD')
|
42
|
+
end
|
43
43
|
|
44
44
|
# The version of the event's payload format and structure
|
45
45
|
config.version = '1.0'
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
49
|
+
#### Multiple Clients
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# in config/initializers/zaikio_loom.rb
|
53
|
+
Zaikio::Loom.configure do |config|
|
54
|
+
config.environment = :sandbox
|
55
|
+
config.version = '1.0'
|
56
|
+
|
57
|
+
config.application 'my_application' do |app|
|
58
|
+
app.password = ENV.fetch('ZAIKIO_LOOM_PASSWORD')
|
59
|
+
end
|
60
|
+
|
61
|
+
config.application 'my_other_app' do |app|
|
62
|
+
app.password = ENV.fetch('ZAIKIO_LOOM_OTHER_APP_PASSWORD')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
49
67
|
### Usage
|
50
68
|
|
51
69
|
Firing events to Zaikio Loom:
|
@@ -58,7 +76,17 @@ Zaikio::Loom.fire_event(
|
|
58
76
|
)
|
59
77
|
```
|
60
78
|
|
61
|
-
This example would publish an event to Zaikio Loom with a random UUID and the current timestamp.
|
79
|
+
This example would publish an event (in the background) to Zaikio Loom with a random UUID and the current timestamp.
|
80
|
+
|
81
|
+
If you want to publish the event for a specific client, you have to add it as part of the event name:
|
82
|
+
|
83
|
+
```rb
|
84
|
+
Zaikio::Loom.fire_event(
|
85
|
+
'my_other_app.event_name',
|
86
|
+
subject: 'Org/3a242896-fa57-41ba-997e-8c212d7157f3',
|
87
|
+
payload: { foo: 'bar', baz: [1, 2, 3] }
|
88
|
+
)
|
89
|
+
```
|
62
90
|
|
63
91
|
If you need more control over the published event, for example:
|
64
92
|
|
data/bin/test
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.active_job.custom_serializers << Zaikio::Loom::EventSerializer
|
data/lib/zaikio/loom.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
require "zaikio/loom/app_configuration"
|
1
2
|
require "zaikio/loom/configuration"
|
2
3
|
require "zaikio/loom/event"
|
4
|
+
require "zaikio/loom/event_serializer"
|
5
|
+
require "zaikio/loom/railtie"
|
6
|
+
require "zaikio/loom/engine"
|
3
7
|
require "zaikio/loom/version"
|
4
8
|
|
5
9
|
module Zaikio
|
@@ -15,7 +19,7 @@ module Zaikio
|
|
15
19
|
|
16
20
|
def self.fire_event(name, **args)
|
17
21
|
event = Event.new(name, **args)
|
18
|
-
event
|
22
|
+
FireEventJob.perform_later(event)
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -4,36 +4,32 @@ module Zaikio
|
|
4
4
|
module Loom
|
5
5
|
class Configuration
|
6
6
|
HOSTS = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
sandbox: "https://loom.sandbox.zaikio.com",
|
11
|
-
production: "https://loom.zaikio.com"
|
7
|
+
test: "http://loom.zaikio.test",
|
8
|
+
sandbox: "https://loom.sandbox.zaikio.com",
|
9
|
+
production: "https://loom.zaikio.com"
|
12
10
|
}.freeze
|
13
11
|
|
14
|
-
attr_accessor :
|
15
|
-
attr_reader :environment, :host
|
12
|
+
attr_accessor :version
|
13
|
+
attr_reader :environment, :host, :apps
|
16
14
|
attr_writer :logger
|
17
15
|
|
18
16
|
def initialize
|
19
17
|
@environment = :sandbox
|
18
|
+
@apps = {}
|
20
19
|
end
|
21
20
|
|
22
21
|
def logger
|
23
|
-
@logger ||= Logger.new(
|
22
|
+
@logger ||= Logger.new($stdout)
|
24
23
|
end
|
25
24
|
|
26
25
|
def environment=(env)
|
27
26
|
@environment = env.to_sym
|
28
|
-
@host =
|
27
|
+
@host = HOSTS[environment]
|
29
28
|
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
HOSTS.fetch(environment) do
|
35
|
-
raise StandardError.new, "Invalid Zaikio::Loom environment '#{environment}'"
|
36
|
-
end
|
30
|
+
def application(name)
|
31
|
+
@apps[name.to_s] = AppConfiguration.new(name.to_s)
|
32
|
+
yield(@apps[name.to_s])
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
data/lib/zaikio/loom/event.rb
CHANGED
@@ -5,10 +5,10 @@ require "securerandom"
|
|
5
5
|
module Zaikio
|
6
6
|
module Loom
|
7
7
|
class Event
|
8
|
-
attr_reader :status_code, :response_body
|
8
|
+
attr_reader :id, :status_code, :response_body
|
9
9
|
|
10
|
-
def initialize(name, subject:, id: nil, link: nil, payload: nil, receiver: nil, timestamp: nil, version: nil) # rubocop:disable Metrics/ParameterLists
|
11
|
-
@event_name = "#{configuration.app_name}.#{name}"
|
10
|
+
def initialize(name, subject:, id: nil, link: nil, payload: nil, receiver: nil, timestamp: nil, version: nil) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists
|
11
|
+
@event_name = name.to_s.count(".").zero? ? "#{configuration.apps.values.first.app_name}.#{name}" : name.to_s
|
12
12
|
@id = id || SecureRandom.uuid
|
13
13
|
@link = link
|
14
14
|
@payload = payload
|
@@ -17,13 +17,15 @@ module Zaikio
|
|
17
17
|
@timestamp = timestamp
|
18
18
|
@version = version || configuration.version
|
19
19
|
|
20
|
-
return if
|
20
|
+
return if app_password
|
21
21
|
|
22
22
|
configuration.logger.error("Zaikio::Loom is disabled – event password is missing")
|
23
23
|
end
|
24
24
|
|
25
25
|
def fire # rubocop:disable Metrics/AbcSize
|
26
|
-
|
26
|
+
log_event
|
27
|
+
|
28
|
+
return false unless app_password && configuration.host
|
27
29
|
|
28
30
|
uri = URI("#{configuration.host}/api/v1/events")
|
29
31
|
|
@@ -38,11 +40,34 @@ module Zaikio
|
|
38
40
|
response.is_a?(Net::HTTPSuccess)
|
39
41
|
end
|
40
42
|
|
43
|
+
def to_h # rubocop:disable Metrics/MethodLength
|
44
|
+
timestamp = @timestamp || Time.now.getutc
|
45
|
+
|
46
|
+
{
|
47
|
+
id: @id,
|
48
|
+
name: @event_name,
|
49
|
+
subject: @subject,
|
50
|
+
timestamp: timestamp.iso8601,
|
51
|
+
receiver: @receiver,
|
52
|
+
version: @version,
|
53
|
+
payload: @payload,
|
54
|
+
link: @link
|
55
|
+
}.compact
|
56
|
+
end
|
57
|
+
|
41
58
|
private
|
42
59
|
|
60
|
+
def app_name
|
61
|
+
@event_name.split(".").first
|
62
|
+
end
|
63
|
+
|
64
|
+
def app_password
|
65
|
+
configuration.apps[app_name].password
|
66
|
+
end
|
67
|
+
|
43
68
|
def build_request(uri)
|
44
69
|
Net::HTTP::Post.new(uri, "User-Agent" => "zaikio-loom:#{Zaikio::Loom::VERSION}").tap do |request|
|
45
|
-
request.basic_auth(
|
70
|
+
request.basic_auth(app_name, app_password)
|
46
71
|
request.body = event_as_json
|
47
72
|
request.content_type = "application/json"
|
48
73
|
end
|
@@ -52,24 +77,12 @@ module Zaikio
|
|
52
77
|
Zaikio::Loom.configuration
|
53
78
|
end
|
54
79
|
|
55
|
-
def event_as_json
|
56
|
-
|
80
|
+
def event_as_json
|
81
|
+
@event_as_json ||= Oj.dump({ event: to_h }, mode: :compat)
|
82
|
+
end
|
57
83
|
|
58
|
-
|
59
|
-
|
60
|
-
event: {
|
61
|
-
id: @id,
|
62
|
-
name: @event_name,
|
63
|
-
subject: @subject,
|
64
|
-
timestamp: timestamp.iso8601,
|
65
|
-
receiver: @receiver,
|
66
|
-
version: @version,
|
67
|
-
payload: @payload,
|
68
|
-
link: @link
|
69
|
-
}.compact
|
70
|
-
},
|
71
|
-
mode: :compat
|
72
|
-
)
|
84
|
+
def log_event
|
85
|
+
configuration.logger.info("Zaikio::Loom event\n#{event_as_json}")
|
73
86
|
end
|
74
87
|
end
|
75
88
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Loom
|
3
|
+
class EventSerializer < ActiveJob::Serializers::ObjectSerializer
|
4
|
+
def serialize?(argument)
|
5
|
+
argument.is_a? Event
|
6
|
+
end
|
7
|
+
|
8
|
+
def serialize(event)
|
9
|
+
super(event.to_h.stringify_keys)
|
10
|
+
end
|
11
|
+
|
12
|
+
def deserialize(hash)
|
13
|
+
name = hash.delete("name")
|
14
|
+
timestamp = DateTime.parse(hash.delete("timestamp"))
|
15
|
+
hash.delete("_aj_serialized")
|
16
|
+
Event.new(name, **hash.symbolize_keys.merge(timestamp: timestamp))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/zaikio/loom/version.rb
CHANGED
data/zaikio-loom.gemspec
CHANGED
@@ -23,12 +23,18 @@ Gem::Specification.new do |spec|
|
|
23
23
|
end
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
+
spec.add_dependency "nokogiri", ">= 1.11.0"
|
27
|
+
spec.add_dependency "rails", "~> 6.0", ">= 6.0.2.3"
|
26
28
|
spec.add_runtime_dependency "oj"
|
29
|
+
spec.required_ruby_version = ">= 2.7.1"
|
27
30
|
|
28
31
|
spec.add_development_dependency "bundler"
|
29
32
|
spec.add_development_dependency "minitest"
|
33
|
+
spec.add_development_dependency "mocha"
|
30
34
|
spec.add_development_dependency "rake"
|
31
35
|
spec.add_development_dependency "rubocop"
|
36
|
+
spec.add_development_dependency "rubocop-minitest"
|
32
37
|
spec.add_development_dependency "rubocop-performance"
|
38
|
+
spec.add_development_dependency "rubocop-rake"
|
33
39
|
spec.add_development_dependency "webmock"
|
34
40
|
end
|
metadata
CHANGED
@@ -1,16 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-loom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
8
8
|
- Martin Spickermann
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.11.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.11.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '6.0'
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 6.0.2.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '6.0'
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.0.2.3
|
14
48
|
- !ruby/object:Gem::Dependency
|
15
49
|
name: oj
|
16
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +87,20 @@ dependencies:
|
|
53
87
|
- - ">="
|
54
88
|
- !ruby/object:Gem::Version
|
55
89
|
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: mocha
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
56
104
|
- !ruby/object:Gem::Dependency
|
57
105
|
name: rake
|
58
106
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +129,20 @@ dependencies:
|
|
81
129
|
- - ">="
|
82
130
|
- !ruby/object:Gem::Version
|
83
131
|
version: '0'
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: rubocop-minitest
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
type: :development
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
84
146
|
- !ruby/object:Gem::Dependency
|
85
147
|
name: rubocop-performance
|
86
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +157,20 @@ dependencies:
|
|
95
157
|
- - ">="
|
96
158
|
- !ruby/object:Gem::Version
|
97
159
|
version: '0'
|
160
|
+
- !ruby/object:Gem::Dependency
|
161
|
+
name: rubocop-rake
|
162
|
+
requirement: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
98
174
|
- !ruby/object:Gem::Dependency
|
99
175
|
name: webmock
|
100
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +185,7 @@ dependencies:
|
|
109
185
|
- - ">="
|
110
186
|
- !ruby/object:Gem::Version
|
111
187
|
version: '0'
|
112
|
-
description:
|
188
|
+
description:
|
113
189
|
email:
|
114
190
|
- op@crispymtn.com
|
115
191
|
- spickermann@gmail.com
|
@@ -117,9 +193,9 @@ executables: []
|
|
117
193
|
extensions: []
|
118
194
|
extra_rdoc_files: []
|
119
195
|
files:
|
196
|
+
- ".circleci/config.yml"
|
120
197
|
- ".gitignore"
|
121
198
|
- ".rubocop.yml"
|
122
|
-
- ".travis.yml"
|
123
199
|
- CHANGELOG.md
|
124
200
|
- CODE_OF_CONDUCT.md
|
125
201
|
- Gemfile
|
@@ -127,10 +203,17 @@ files:
|
|
127
203
|
- LICENSE.txt
|
128
204
|
- README.md
|
129
205
|
- Rakefile
|
206
|
+
- app/jobs/zaikio/loom/fire_event_job.rb
|
130
207
|
- bin/setup
|
208
|
+
- bin/test
|
209
|
+
- config/initializers/register_zaikio_loom_event_serializer.rb
|
131
210
|
- lib/zaikio/loom.rb
|
211
|
+
- lib/zaikio/loom/app_configuration.rb
|
132
212
|
- lib/zaikio/loom/configuration.rb
|
213
|
+
- lib/zaikio/loom/engine.rb
|
133
214
|
- lib/zaikio/loom/event.rb
|
215
|
+
- lib/zaikio/loom/event_serializer.rb
|
216
|
+
- lib/zaikio/loom/railtie.rb
|
134
217
|
- lib/zaikio/loom/version.rb
|
135
218
|
- zaikio-loom.gemspec
|
136
219
|
homepage: https://github.com/crispymtn/zai-loom-ruby
|
@@ -140,7 +223,7 @@ metadata:
|
|
140
223
|
changelog_uri: https://github.com/crispymtn/zai-loom-ruby/blob/master/CHANGELOG.md
|
141
224
|
homepage_uri: https://github.com/crispymtn/zai-loom-ruby
|
142
225
|
source_code_uri: https://github.com/crispymtn/zai-loom-ruby
|
143
|
-
post_install_message:
|
226
|
+
post_install_message:
|
144
227
|
rdoc_options: []
|
145
228
|
require_paths:
|
146
229
|
- lib
|
@@ -148,15 +231,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
231
|
requirements:
|
149
232
|
- - ">="
|
150
233
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
234
|
+
version: 2.7.1
|
152
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
236
|
requirements:
|
154
237
|
- - ">="
|
155
238
|
- !ruby/object:Gem::Version
|
156
239
|
version: '0'
|
157
240
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
159
|
-
signing_key:
|
241
|
+
rubygems_version: 3.2.3
|
242
|
+
signing_key:
|
160
243
|
specification_version: 4
|
161
244
|
summary: The Zaikio Loom Ruby Gem simplifies publishing events on the Zaikio Loom
|
162
245
|
event system.
|