[jrubyscripting] Accept generic global variable names (#12539)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2022-04-02 07:17:03 +10:00 committed by GitHub
parent e8c944281a
commit 77c765085e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,9 +48,6 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory {
// difficult ways to debug.
private static final Set<String> FILTERED_PRESETS = Set.of("File", "Files", "Path", "Paths");
private static final Set<String> INSTANCE_PRESETS = Set.of();
private static final Set<String> GLOBAL_PRESETS = Set.of("scriptExtension", "automationManager", "ruleRegistry",
"items", "voice", "rules", "things", "events", "itemRegistry", "ir", "actions", "se", "audio",
"lifecycleTracker");
private final javax.script.ScriptEngineFactory factory = new org.jruby.embed.jsr223.JRubyEngineFactory();
@ -69,7 +66,8 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory {
// Adds $ in front of a set of variables so that Ruby recognizes them as global variables
private static Map.Entry<String, Object> mapGlobalPresets(Map.Entry<String, Object> entry) {
if (GLOBAL_PRESETS.contains(entry.getKey())) {
if (Character.isLowerCase(entry.getKey().charAt(0)) && !(entry.getValue() instanceof Class)
&& !(entry.getValue() instanceof Enum)) {
return Map.entry("$" + entry.getKey(), entry.getValue());
} else {
return entry;