Class: Jets::Shim::Adapter::Fallback

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/shim/adapter/fallback.rb

Instance Attribute Summary

Attributes inherited from Base

#context, #event, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Util::Logging

#log

Constructor Details

This class inherits a constructor from Jets::Shim::Adapter::Base

Class Method Details

.handler(event, context = nil, target = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jets/shim/adapter/fallback.rb', line 13

def handler(event, context = nil, target = nil)
  puts "    WARN: handler for it could not be found. The default fallback handler is being used.\n    The default fallback handler simply prints out the event payload for debugging, it will be printed below.\n    Usually the default handler is not what you want.\n    You might be using a test event payload for testing which does not represent a real event.\n    Please double check the event payload.\n  EOL\n  if ENV[\"_HANDLER\"] # on AWS Lambda\n    puts \"event: \#{JSON.dump(event)}\"\n  else\n    puts \"event:\"\n    puts JSON.pretty_generate(event)\n  end\n\n  if target\n    puts \"WARN: Event handler target not found: \#{target}\".color(:red)\n    target_class, target_method = target.split(\".\")\n    target_class = target_class.camelize\n    target_method ||= \"perform\"\n    puts <<~EOL\n      You can configure define an app/events handler in your application. Example:\n\n      app/events/\#{target_class.underscore}.rb\n\n          class \#{target_class} < ApplicationEvent\n            def \#{target_method}\n              puts \"event \#{JSON.dump(event)}\"\n            end\n          end\n    EOL\n\n  else\n    puts <<~EOL\n      You can also configure a custom fallback handler with a config/jets/shim.rb file.\n      Though custom handlers rarely needed and you should double check the event payload.\n      Example:\n\n      config/jets/shim.rb\n\n          Jets.shim.configure do |config|\n            config.fallback_handler = FallbackHandler\n          end\n\n      FallbackHandler should implement handler(event, context)\n\n    EOL\n  end\n  # Custom Jets error message\n  {\n    errorMessage: \"Event handler not found. Look at logs for details\",\n    errorType: \"JetsEventHandlerNotFound\"\n  }\nend\n"

Instance Method Details

#fallback_handlerObject



7
8
9
# File 'lib/jets/shim/adapter/fallback.rb', line 7

def fallback_handler
  Jets::Shim.config.fallback_handler || self.class
end

#handleObject



3
4
5
# File 'lib/jets/shim/adapter/fallback.rb', line 3

def handle
  fallback_handler.handler(event, context, target)
end