Class: Jets::Shim::Handler

Inherits:
Object
  • Object
show all
Extended by:
Util::Logging
Includes:
Util::Logging
Defined in:
lib/jets/shim/handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

log

Constructor Details

#initialize(event, context = nil, target = nil) ⇒ Handler

Returns a new instance of Handler.



6
7
8
9
10
# File 'lib/jets/shim/handler.rb', line 6

def initialize(event, context = nil, target = nil)
  @event = event.deep_stringify_keys
  @context = context
  @target = target # IE: cool_event.party
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/jets/shim/handler.rb', line 5

def context
  @context
end

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/jets/shim/handler.rb', line 5

def event
  @event
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/jets/shim/handler.rb', line 5

def target
  @target
end

Class Method Details

.show_debug_shim(message, payload) ⇒ Object

interface method used by Shim::Response::Base



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jets/shim/handler.rb', line 46

def show_debug_shim(message, payload)
  return unless ENV["JETS_DEBUG_SHIM"]

  log.info message
  # pretty mode is not useful on CloudWatch since it strips the surrounding spaces on each line
  # It's only useful for testing handlers locally
  if ENV["JETS_DEBUG_SHIM"] == "pretty"
    log.info JSON.pretty_generate(payload)
  else
    log.info JSON.dump(payload) # json one line
  end
end

Instance Method Details

#adapterObject



17
18
19
20
21
# File 'lib/jets/shim/handler.rb', line 17

def adapter
  adapter_class = Adapter.const_get(adapter_name.to_s.camelize)
  log.info "jets shim adapter: #{adapter_name}" if ENV["JETS_DEBUG_SHIM"]
  adapter_class.new(event, context, target) # IE: Adapter::Apigw
end

#handleObject



12
13
14
15
# File 'lib/jets/shim/handler.rb', line 12

def handle
  show_debug_shim_event
  adapter.handle
end