Sha256: 81cfc35d4c647156f73c1d8df749463d1c3e98cd17f3091a5fb91779f5796f80

Contents?: true

Size: 1.37 KB

Versions: 32

Compression:

Stored size: 1.37 KB

Contents

const AbstractHandler = require("./AbstractHandler");

class InvokeGlobalMethodHandler extends AbstractHandler {
  requiredParametersCount = 1;

  constructor() {
    super();
  }

  process(command) {
    try {
      if (command.payload.length < this.requiredParametersCount) {
        throw new Error("Invoke Global Method parameters mismatch");
      }
      const { payload } = command;
      const splitted = payload[0].split(".");
      let methodToInvoke;
      for (let i = 0; i < splitted.length; i++) {
        methodToInvoke = !methodToInvoke
          ? global[splitted[i]]
          : methodToInvoke[splitted[i]];
      }
      if (typeof methodToInvoke === "undefined") {
        let methods = Object.getOwnPropertyNames(global).filter(function (
          property
        ) {
          return typeof global[property] === "function";
        });
        let message = `Method ${payload[0]} not found in global. Available methods:\n`;
        methods.forEach((methodIter) => {
          message += `${methodIter}\n`;
        });
        throw new Error(message);
      }
      if (payload.length > 1) {
        const args = payload.slice(1);
        return methodToInvoke(args);
      } else {
        return methodToInvoke();
      }
    } catch (error) {
      throw this.process_stack_trace(error, this.constructor.name);
    }
  }
}

module.exports = new InvokeGlobalMethodHandler();

Version data entries

32 entries across 21 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.8 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/InvokeGlobalMethodHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/InvokeGlobalMethodHandler.js