Class: Wisco::ExecScript::ScriptHost
- Inherits:
-
Object
- Object
- Wisco::ExecScript::ScriptHost
- Defined in:
- lib/wisco/exec_script.rb
Overview
Host object that the script is eval’d against. Exposes the helper API. Defined as a class (not a Module) so ‘instance_eval` gives the script access to standard top-level Ruby plus our helpers, without polluting Object globally.
Instance Method Summary collapse
-
#call_method(name, *args) ⇒ Object
Invoke a connector ‘methods:` entry.
-
#call_pick_list(name, **args) ⇒ Object
Invoke a connector ‘pick_lists:` entry.
-
#connection ⇒ Object
Hash of decrypted settings for the configured connection.
-
#initialize(connector_full_path, target_dir, connection_name) ⇒ ScriptHost
constructor
A new instance of ScriptHost.
Constructor Details
#initialize(connector_full_path, target_dir, connection_name) ⇒ ScriptHost
Returns a new instance of ScriptHost.
58 59 60 61 62 63 64 65 66 |
# File 'lib/wisco/exec_script.rb', line 58 def initialize(connector_full_path, target_dir, connection_name) @connector_full_path = connector_full_path @target_dir = target_dir @connection_name = connection_name || 'default' @sdk_connector = nil @connection_loaded = false @connection_cached = nil @warned_settings = false end |
Instance Method Details
#call_method(name, *args) ⇒ Object
Invoke a connector ‘methods:` entry. Args are forwarded to the lambda as-is. Returns the lambda’s return value.
Example:
call_method(:format_timestamp, Time.now)
82 83 84 85 86 87 88 |
# File 'lib/wisco/exec_script.rb', line 82 def call_method(name, *args) proxy = sdk_connector.methods unless proxy.respond_to?(name.to_sym) raise InvalidReturn, "No methods entry named '#{name}' found in connector." end proxy.public_send(name.to_sym, *args) end |
#call_pick_list(name, **args) ⇒ Object
Invoke a connector ‘pick_lists:` entry. `args` is a Hash of named arguments for dependent pick lists. The SDK supplies `connection` to the lambda automatically.
Examples:
call_pick_list(:active_customers)
call_pick_list(:customer_orders, customer_id: 123)
97 98 99 100 101 102 103 104 105 |
# File 'lib/wisco/exec_script.rb', line 97 def call_pick_list(name, **args) proxy = sdk_connector.pick_lists unless proxy.respond_to?(name.to_sym) raise InvalidReturn, "No pick_lists entry named '#{name}' found in connector." end # SDK signature: pick_list_name(settings = nil, args = {}) # Passing nil for settings tells the SDK to reuse the connector's settings. proxy.public_send(name.to_sym, nil, args) end |
#connection ⇒ Object
Hash of decrypted settings for the configured connection. Returns {} and emits a one-time warning if settings can’t be loaded.
70 71 72 73 74 75 |
# File 'lib/wisco/exec_script.rb', line 70 def connection return @connection_cached if @connection_loaded @connection_loaded = true @connection_cached = load_connection end |