You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find yourself missing a `rails console` analogue in your other Ruby web applications? This lightweight gem provides a Rack::Console class that will load your Rack application's code and environment into an IRB or Pry session. Either use `Rack::Console.new.start` directly, or run the provided `rack-console` executable.
3
+
Find yourself missing a `rails console` analogue in your other Ruby web applications? This lightweight gem provides a Rack::Console class that will load your Rack application's code and environment into an IRB or Pry session. Either use `Rack::Console.new(options).start` directly, or run the provided `rack-console` executable.
4
4
5
5
## Installation
6
6
7
7
Add this line to your application's Gemfile:
8
8
9
9
```ruby
10
-
gem 'rack-console'
10
+
gem "rack-console"
11
11
```
12
12
13
13
And then execute:
@@ -25,47 +25,46 @@ $ gem install rack-console
25
25
## Usage
26
26
27
27
Rack::Console ships with a `rack-console` executable that will load your application in an IRB shell (or
28
-
[Pry](http://pryrepl.org) if that's included in your Gemfile). Assuming you have a `config.ru` file in the current directory, simply run:
28
+
[Pry](http://pryrepl.org) if that's included in your Gemfile and you specify the `--pry` option). Assuming you have a `config.ru` file in the current directory, simply run:
29
29
30
-
```ruby
30
+
```
31
31
$ bundle exec rack-console
32
-
pry(main)>
32
+
Loading development environment (Rack::Console 2.0.0)
33
+
irb(main):001>
33
34
```
34
35
35
-
Rack::Console supports some of the same things that `rails console` provides, as well as arguments used in `rackup`:
36
+
Rack::Console supports some of the same things that `rails console` provides, as well as some of the options used in `rackup`:
36
37
37
38
* An `app` method that will return your underlying Rack application with [rack-test](https://github.com/brynary/rack-test) methods mixed in. You can perform fake requests to your app (e.g. `response = app.get('/')`)
38
-
* Supply the RACK_ENV as an argument (`bundle exec rack-console production`)
39
39
* A `reload!` method to discard new code or defined variables/constants
40
40
* The `-c` option (or `--config`) to specify a non-standard `config.ru` file
41
+
* The `-e` option (or `--environment`) to specify the Rack environment to load
41
42
* The `-r` option (or `--require`) to require a file/library before Rack::Console loads
42
43
* The `-I` option (or `--include`) to specify paths (colon-separated) to add to `$LOAD_PATH` before Rack::Console loads
44
+
* The `-P` option (or `--[no-]pry`) to specify whether to use Pry instead of IRB (Pry must be installed in your project)
43
45
44
46
## Framework CLI Example
45
47
46
-
Because Rack::Console is just a class, it's easy to provide a `console` subcommand to a CLI for your own Rack framework. For example, here's how you could hypothetically implement a `console` subcommand for a generic Rack CLI using [Thor](https://github.com/erikhuda/thor):
48
+
Because Rack::Console is just a class, it's easy to provide a `console` subcommand to a CLI for your own Rack framework. For example, here's how you could hypothetically implement a `console` subcommand for a generic Rack CLI using [Thor](https://github.com/rails/thor):
47
49
48
50
```ruby
49
-
require'rack/console'
50
-
require'thor'
51
+
require"rack/console"
52
+
require"thor"
51
53
52
54
moduleRack
53
55
classCLI < Thor
54
-
desc 'console [ENVIRONMENT]', 'Start a Rack console'
56
+
desc "console [ENVIRONMENT]", "Start a Rack console"
0 commit comments