hasura_handler 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/hasura_handler/events_controller.rb +1 -1
- data/app/jobs/hasura_handler/event_handler_job.rb +1 -1
- data/app/jobs/hasura_handler/event_job.rb +1 -1
- data/lib/hasura_handler.rb +1 -0
- data/lib/hasura_handler/event.rb +8 -6
- data/lib/hasura_handler/event_handler.rb +2 -0
- data/lib/hasura_handler/event_processor.rb +7 -2
- data/lib/hasura_handler/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: 391dc0c3183a5a8ac53709ee48c14a0ee5fae6c085a21d200972556b732fcd1a
|
4
|
+
data.tar.gz: 32122de81ca8c930934383944f0387bdeb9e566a026aea488be203f0610d7137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 687179bd480090e6a46e06f63aff4901f3b609f3321f91aba92b6a238a140bbb7220723261a25ce44cf30ce3dddbc023eded6e9e98c16c25a19bda3448b2928d
|
7
|
+
data.tar.gz: e7b506c5cd0904a626390b9ed76e02d0da34729b9299264b5457fb248dcc398d134a198364fdca36768111b1a5cd3ceabcd69042cd1505e9f5b956ccc7fdc354
|
@@ -3,7 +3,7 @@ require_dependency 'hasura_handler/application_controller'
|
|
3
3
|
module HasuraHandler
|
4
4
|
class EventsController < ApplicationController
|
5
5
|
def index
|
6
|
-
processor = HasuraHandler::
|
6
|
+
processor = HasuraHandler::EventProcessor.new(event_params.to_h)
|
7
7
|
|
8
8
|
unless processor.event.valid?
|
9
9
|
error_response(processor.event.errors)
|
data/lib/hasura_handler.rb
CHANGED
data/lib/hasura_handler/event.rb
CHANGED
@@ -4,6 +4,7 @@ module HasuraHandler
|
|
4
4
|
:table,
|
5
5
|
:trigger,
|
6
6
|
:event,
|
7
|
+
:op,
|
7
8
|
:created_at,
|
8
9
|
:raw_event,
|
9
10
|
:errors,
|
@@ -11,9 +12,10 @@ module HasuraHandler
|
|
11
12
|
|
12
13
|
def initialize(event)
|
13
14
|
@id = event['id']
|
14
|
-
@table = event['table']
|
15
|
-
@trigger = event['trigger']
|
15
|
+
@table = event['table']['name']
|
16
|
+
@trigger = event['trigger']['name']
|
16
17
|
@event = event['event']
|
18
|
+
@op = event['event']['op']
|
17
19
|
@created_at = event['created_at']
|
18
20
|
@raw_event = event
|
19
21
|
@errors = {}
|
@@ -42,21 +44,21 @@ module HasuraHandler
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def validate_table
|
45
|
-
unless @table.is_a?(Hash)
|
47
|
+
unless @raw_event['table'].is_a?(Hash)
|
46
48
|
@errors['table'] = 'not a hash'
|
47
49
|
return
|
48
50
|
end
|
49
51
|
|
50
|
-
string_fields?(@table, 'table', [:schema, :name])
|
52
|
+
string_fields?(@raw_event['table'], 'table', [:schema, :name])
|
51
53
|
end
|
52
54
|
|
53
55
|
def validate_trigger
|
54
|
-
unless @trigger.is_a?(Hash)
|
56
|
+
unless @raw_event['trigger'].is_a?(Hash)
|
55
57
|
@errors['trigger'] = 'not a hash'
|
56
58
|
return
|
57
59
|
end
|
58
60
|
|
59
|
-
string_fields?(@trigger, 'trigger', [:name])
|
61
|
+
string_fields?(@raw_event['trigger'], 'trigger', [:name])
|
60
62
|
end
|
61
63
|
|
62
64
|
def validate_event
|
@@ -19,6 +19,10 @@ module HasuraHandler
|
|
19
19
|
handler.run
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
if event_handlers.size == 0
|
24
|
+
Rails.logger.debug('[HasuraHandler] Received event with no matching handlers.')
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
@@ -28,6 +32,7 @@ module HasuraHandler
|
|
28
32
|
descendants.
|
29
33
|
map{ |klass| [klass, klass.hasura_matchers] }.
|
30
34
|
to_h.
|
35
|
+
select{ |klass, matchers| matchers.present? }.
|
31
36
|
map{ |klass,matchers| [klass, check_matchers(matchers)] }.
|
32
37
|
to_h.
|
33
38
|
select{ |klass,match| match }.
|
@@ -35,8 +40,8 @@ module HasuraHandler
|
|
35
40
|
end
|
36
41
|
|
37
42
|
def check_matchers(matchers)
|
38
|
-
matchers.all? do |
|
39
|
-
@event.send(
|
43
|
+
matchers.all? do |field,value|
|
44
|
+
@event.send(field) == value
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|