0.0
No commit activity in last 3 years
No release in over 3 years
This Rails plugin is enable to add command easily to `rails console` even if it is using which of pry and irb
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.2
 Project Readme

ConsoleCommand

This Rails plugin is enable to add command easily to rails console even if it is using which of pry and irb.

Usage

In your Gemfile.

group :development do
  gem "console_command"
end

and puts ruby script as follows in config/console_command/. Some examples are in examples/

# config/console_command/what_time_is_it_now.rb
# CC aliased to ConsoleCommand
CC.define_command('what-time-is-it-now') do |c|
  c.description "display current time" # this infomation is used only by pry
  c.group "Joke"                       # this infomation is used only by pry
  c.options do |opts|                  # this infomation is used only by pry
    opt.banner unindent <<-USAGE
      Usage: what-time-is-it-now

      display what-time-is-it-now
    USAGE
  end
  c.process do
    puts Time.now
  end
end

and start rails console and execute command.

If you use irb for rails console, hyphen in command name is automatically converted to underscore. Because we can't use hyphen for command name in irb

# with pry
$ rails console
[1] pry(main)> what-time-is-it-now
2012-12-22 17:26:26 +0900
[2] pry(main)> help
...
Joke
  what-time-is-it-now display current time
...

# with irb
$ rails console
irb(main):001:0> what_time_is_it_now
2012-12-22 17:26:26 +0900