@freestyle-sh/with-ruby
Ruby runtime via RVM for Freestyle VMs.
Installation
npm install @freestyle-sh/with-ruby freestyle-sandboxes
Usage
import { freestyle } from "freestyle-sandboxes";
import { VmRuby } from "@freestyle-sh/with-ruby";
const { vm } = await freestyle.vms.create({
with: {
ruby: new VmRuby(),
},
});
const res = await vm.ruby.runCode({
code: "require 'json'; puts JSON.generate({ hello: 'world' })"
});
console.log(res);
Options
new VmRuby({
version: "3.3.6",
})
version | string | "3.4.8" | Ruby version to install via RVM. |
API
vm.ruby.runCode({ code: string })
Executes Ruby code in the RVM-managed Ruby runtime.
Returns: Promise<RunCodeResponse>
type RunCodeResponse<Result> = {
result: Result;
stdout?: string;
stderr?: string;
statusCode?: number;
};
vm.ruby.install(options?)
Installs gems via gem install or bundle install.
Returns: Promise<InstallResult>
await vm.ruby.install({ deps: ["nokogiri", "colorize"] });
await vm.ruby.install();
await vm.ruby.install({ directory: "/app" });
type InstallOptions =
| { deps: string[] }
| { directory?: string; deps?: undefined };
type InstallResult = {
success: boolean;
stdout?: string;
stderr?: string;
};
Documentation