0.2.0 • Published 2 years ago

rails-console v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

rails-console.js

Rails interface in Node.js via Rails console

NPM Version NPM Downloads License: MIT

⚙ Install

# npm
npm i rails-console

# yarn
yarn add rails-console

🔍 Usage

const { RailsConsole } = require('rails-console');

async run() {
  const rc = new RailsConsole();
  // Or:
  const rcWithOptions = new RailsConsole({
    cwd: path.resolve(__dirname, 'rails-app'), // Optionally specify directory where to start rails console
  });

  // Wait for the rails console process to start
  await rc.start();

  // Get application name
  const result = await rc.send('Rails.application.engine_name.gsub(/_application$/,"")');
  if (result.success) {
    console.log(`Name of the Rails app: ${result.returnValue}`);
  } else {
    console.log(`Command returned an error: ${result.error}`);
  }
  if (result.raw.stderr) {
    console.log(`Command output warnings: ${result.raw.stderr}`);
  }

  // Update an ActiveRecord item
  await rc.send('User.find(1).update(name: "First User")');

  // Stop the process
  rc.stop();
}

️❤️ Contributing

Every contribution is really welcome!

If you feel that something can be improved or should be fixed, feel free to open an issue with the feature or the bug found.

If you want to fork and open a pull request (adding features or fixes), feel free to do it.

Read the contributing guidelines

📃 Licence

Read the licence

0.2.0

2 years ago

0.1.0

2 years ago