D4C Build Status

Easy add options to Rails console

Prerequisites

  • Rails >= 5.1.0 Application ## Installation Add this line to your application's Gemfile:
gem 'd4c'

And then execute:

$ bundle

Or install it yourself as:

$ gem install d4c

Usage

Add option in config/application.rb

# frozen_string_literal: true

require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)

D4C::Console.add_option 'hello' do
  puts "hello"
end

module YourRailsApplication
  class Application < Rails::Application

Note

You need to put D4C::Console.add_option before YourRailsApplication module.
see also: https://guides.rubyonrails.org/configuring.html#running-code-before-rails

Option Description

you can set option description

D4C::Console.add_option 'hello', 'say hello!' do
  puts "hello"
end
$rails c -h
Running via Spring preloader in process 13861
Usage:
  bin/rails console [environment] [options]

Options:
  -e, [--environment=ENVIRONMENT]  # Specifies the environment to run this console under (test/development/production).
  -s, [--sandbox], [--no-sandbox]  # Rollback database modifications on exit.
      [--hello], [--no-hello]      # say hello

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/QWYNG/d4c. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.