Module: Wisco::ExecScript

Defined in:
lib/wisco/exec_script.rb

Overview

Evaluates an ‘execute_*.rb` script and returns the value of its last expression. The script is eval’d inside a binding that exposes helpers (‘call_method`, `call_pick_list`, `connection`) so the script can build dynamic input that varies per run.

Defined Under Namespace

Classes: InvalidReturn, ScriptHost

Constant Summary collapse

SENTINEL_REGEX =
/\A\s*#\s*WISCO_SKIP\b/.freeze

Class Method Summary collapse

Class Method Details

.evaluate(script_path:, connector_full_path:, target_dir:, connection_name: 'default') ⇒ Object

Evaluates the script at ‘script_path` and returns the value of its last expression. Raises StandardError subclasses on:

- syntax / runtime errors in the script
- invalid return value (must be a Hash or Array)

‘connector_full_path` — absolute path to connector.rb (used to build

the SDK Connector for helper invocations).

‘target_dir` — connector project root (used to find

settings.yaml(.enc) + master.key).

‘connection_name` — connection key inside settings.yaml; defaults to ’default’.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wisco/exec_script.rb', line 37

def evaluate(script_path:, connector_full_path:, target_dir:, connection_name: 'default')
  host   = ScriptHost.new(connector_full_path, target_dir, connection_name)
  source = File.read(script_path)
  result = host.instance_eval(source, script_path, 1)

  unless result.is_a?(Hash) || result.is_a?(Array)
    raise InvalidReturn,
          "Script must return a Hash (for actions/triggers) or Array/Hash (for methods/pick_lists). " \
          "Got: #{result.class}"
  end

  result
end

.sentinel?(path) ⇒ Boolean

Returns true if the file’s first non-blank line is a ‘# WISCO_SKIP` comment, in which case the script should be skipped by `wisco exec`.

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'lib/wisco/exec_script.rb', line 16

def sentinel?(path)
  File.foreach(path) do |line|
    stripped = line.strip
    next if stripped.empty?
    return SENTINEL_REGEX.match?(line)
  end
  false
rescue StandardError
  false
end