-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Resolves #14] Adds custom console methods
- Loading branch information
1 parent
aef2461
commit 085e8e5
Showing
2 changed files
with
36 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Apartment | ||
module CustomConsole | ||
begin | ||
require 'pry-rails' | ||
rescue LoadError | ||
puts '[Failed to load pry-rails] If you want to use Apartment custom prompt you need to add pry-rails to your gemfile' | ||
end | ||
|
||
if Pry::Prompt.respond_to?(:add) | ||
desc = "Includes the current Rails environment and project folder name.\n" \ | ||
'[1] [project_name][Rails.env][Apartment::Tenant.current] pry(main)>' | ||
|
||
Pry::Prompt.add 'ros', desc, %w[> *] do |target_self, nest_level, pry, sep| | ||
"[#{pry.input_ring.size}] [#{PryRails::Prompt.formatted_env}][#{Apartment::Tenant.current}] " \ | ||
"#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \ | ||
"#{":#{nest_level}" unless nest_level.zero?}#{sep} " | ||
end | ||
|
||
Pry.config.prompt = Pry::Prompt[:ros][:value] | ||
end | ||
end | ||
end |