Sha256: f727a9f6a2c729f3257a6878e5f77a52dce99dff33ca9c670ceb713b03e3dbd4
Contents?: true
Size: 1.32 KB
Versions: 5
Compression:
Stored size: 1.32 KB
Contents
require 'base64' module FaaStRuby class Runner include RunnerMethods def initialize @rendered = false end def path @path end def load_function(path) eval "Module.new do; #{File.read(path)};end" end def call(workspace_name, function_name, event, args) @short_path = "#{workspace_name}/#{function_name}" @path = "#{FaaStRuby::PROJECT_ROOT}/#{workspace_name}/#{function_name}" short_path = "#{workspace_name}/#{function_name}" begin Dir.chdir(@path) function = load_function("#{@path}/handler.rb") runner = FunctionObject.new(short_path) runner.extend(function) response = runner.handler(event, *args) # response = handler(event, args) return response if response.is_a?(FaaStRuby::Response) body = { 'error' => "Please use the helpers 'render' or 'respond_with' as your function return value." } FaaStRuby::Response.new(body: Oj.dump(body), status: 500, headers: {'Content-Type' => 'application/json'}) rescue Exception => e body = { 'error' => e.message, 'location' => e.backtrace&.first, } FaaStRuby::Response.new(body: Oj.dump(body), status: 500, headers: {'Content-Type' => 'application/json'}) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems