Pry
Use Pry as your rails console
Used 64 times
V
Viktor Schmidt
Usage
RubyGems: https://rubygems.org/gems/pry-rails
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/Xo5sbm"
Template Source
Review the code before running this template on your machine.
def do_bundle
Bundler.with_original_env { run "bundle install" }
end
def print_green(heredoc)
puts set_color heredoc, :green
end
def do_commit
git :init
git add: "."
git commit: " -m 'Add Pry as your rails console' "
end
def has_pry_prompt_in_pryrc?
@has_pry_prompt_in_pryrc ||= begin
checker_regex = /Pry.config.prompt/
File.read(".pryrc")[checker_regex]
end
end
say "\nApplying Pry as your rails console..."
inject_into_file 'Gemfile', after: 'group :development, :test do' do
<<-RUBY
# Use Pry as your rails console
gem "pry-rails"
gem "pry-byebug", platform: :ruby
RUBY
end
do_bundle
create_file ".pryrc", "" unless File.exist? ".pryrc"
unless has_pry_prompt_in_pryrc?
prepend_file ".pryrc" do
<<~EOF
Pry.config.prompt = PryRails::RAILS_PROMPT if defined?(PryRails::RAILS_PROMPT)
EOF
end
end
say "\nAdding documentation for developers..."
create_file "doc/miscellaneous.md", "# Miscellaneous\n" unless File.exist? "doc/miscellaneous.md"
append_file "doc/miscellaneous.md" do
<<~EOF
## IRB console
Add to your `~/.irbrc`:
```bash
require 'irb/completion'
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:AUTO_INDENT_MODE] = false
IRB.conf[:SAVE_HISTORY] = 2000
```
### Pry for Rails console
[Pry](https://rubygems.org/gems/pry) is a runtime developer console and IRB
alternative with powerful introspection capabilities. Pry aims to be more than
an IRB replacement. It is an attempt to bring [REPL driven programming](https://pry.github.io/)
to the Ruby language.
[byebug](https://rubygems.org/gems/pry-byebug) adds 'step', 'next', 'finish', 'continue'
and 'break' commands to control execution.
Add to your `~/.pryrc`:
```bash
Pry.config.prompt = PryRails::RAILS_PROMPT if defined?(PryRails::RAILS_PROMPT)
```
EOF
end
do_commit
print_green "\nAdded Pry successfully!"