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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f772550a50cbdcfdcebd62cc96813060cd16a10c0bb6196a7405c6fa418c915a
4
- data.tar.gz: 85b8df94f285c9fa393dc1d05126af92dfec690f5ff16092a317d6a494355905
3
+ metadata.gz: 391dc0c3183a5a8ac53709ee48c14a0ee5fae6c085a21d200972556b732fcd1a
4
+ data.tar.gz: 32122de81ca8c930934383944f0387bdeb9e566a026aea488be203f0610d7137
5
5
  SHA512:
6
- metadata.gz: b263514fe1d23d90c422a933c14ee3ac0e69c7a681702fdbfc85f7ec65bf66f5f738dbf4ebc2c2a54e032ab84cbba143b7f9a73e39d12ffa532b0e816157024f
7
- data.tar.gz: 636455f631df28448915c2a3fa8c2fe79348c453845dc1b30a30bbf879ff15a3e5126da6a31216e1cdb620dc000b936a00bb14f69a620661685fed995ee3192e
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::EventHandler.new(event_params.to_h)
6
+ processor = HasuraHandler::EventProcessor.new(event_params.to_h)
7
7
 
8
8
  unless processor.event.valid?
9
9
  error_response(processor.event.errors)
@@ -4,7 +4,7 @@ module HasuraHandler
4
4
 
5
5
  def perform(handler_class, event)
6
6
  klass = handler_class.constantize
7
- handler = klass.new(event)
7
+ handler = klass.new(HasuraHandler::Event.new(event))
8
8
  handler.run
9
9
  end
10
10
  end
@@ -3,7 +3,7 @@ module HasuraHandler
3
3
  queue_as HasuraHandler.event_job_queue
4
4
 
5
5
  def perform(event)
6
- HasuraHandler::EventHandler.new(event).process
6
+ HasuraHandler::EventProcessor.new(event).process
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,6 @@
1
1
  require 'hasura_handler/engine'
2
2
  require 'hasura_handler/event_handler'
3
+ require 'hasura_handler/event_processor'
3
4
  require 'hasura_handler/event'
4
5
  require 'hasura_handler/action'
5
6
 
@@ -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
@@ -16,6 +16,8 @@ module HasuraHandler
16
16
  end
17
17
  end
18
18
 
19
+ attr_reader :event
20
+
19
21
  def initialize(event)
20
22
  @event = event
21
23
  end
@@ -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 |matcher|
39
- @event.send(matcher.first) == matcher.last
43
+ matchers.all? do |field,value|
44
+ @event.send(field) == value
40
45
  end
41
46
  end
42
47
  end
@@ -1,3 +1,3 @@
1
1
  module HasuraHandler
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hasura_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaz Walker