Module: FuncE

Defined in:
lib/func_e.rb,
lib/railtie.rb,
lib/func_e/func.rb,
lib/func_e/http.rb,
lib/func_e/config.rb

Overview

Path: func_e/lib/func_e/config.rb

Defined Under Namespace

Modules: Http Classes: Config, Func, Railtie

Constant Summary collapse

RUNNER_PATH =
"#{File.expand_path(__dir__)}/func_e_runner.js"
SERVER_PATH =
"#{File.expand_path(__dir__)}/func_e_server.js"

Class Method Summary collapse

Class Method Details

.exec(func) ⇒ Object



17
18
19
# File 'lib/func_e.rb', line 17

def self.exec(func)
  Config.config.local_server ? server(func) : runner(func)
end

.json_parse(json) ⇒ Object



37
38
39
# File 'lib/func_e.rb', line 37

def self.json_parse(json)
  JSON.parse(json, symbolize_names: true)
end

.lineObject



33
34
35
# File 'lib/func_e.rb', line 33

def self.line
  Terrapin::CommandLine.new("node #{RUNNER_PATH}", '--path=:path --payload=:payload')
end

.runner(func) ⇒ Object



27
28
29
30
31
# File 'lib/func_e.rb', line 27

def self.runner(func)
  json_parse line.run(path: func.path, payload: func.serialize_payload)
rescue Terrapin::CommandLineError => e
  { error: 'An error occurred while executing the node function.', message: e.message }
end

.server(func) ⇒ Object



21
22
23
24
25
# File 'lib/func_e.rb', line 21

def self.server(func)
  json_parse FuncE::Http.post(func).body
rescue Errno::ECONNREFUSED
  { error: 'The server is not running. Please start the server before executing functions.' }
end