Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Rails prompt on v0.12+ #105

Merged
merged 1 commit into from
Nov 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lib/pry-rails/prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@ def project_name
end
end

RAILS_PROMPT = [
proc do |target_self, nest_level, pry|
"[#{pry.input_array.size}] " \
"[#{Prompt.project_name}][#{Prompt.formatted_env}] " \
"#{Pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \
"#{":#{nest_level}" unless nest_level.zero?}> "
end,
proc do |target_self, nest_level, pry|
desc = "Includes the current Rails environment and project folder name.\n" \
"[1] [project_name][Rails.env] pry(main)>"
if Pry::Prompt.respond_to?(:add)
Pry::Prompt.add 'rails', desc, %w(> *) do |target, nesting, _pry_, sep|
"[#{pry.input_ring.size}] " \
"[#{Prompt.project_name}][#{Prompt.formatted_env}] " \
"#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \
"#{":#{nest_level}" unless nest_level.zero?}#{sep} "
end
else
draw_prompt = lambda do |target_self, nest_level, pry, sep|
"[#{pry.input_array.size}] " \
"[#{Prompt.project_name}][#{Prompt.formatted_env}] " \
"#{Pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \
"#{":#{nest_level}" unless nest_level.zero?}* "
"[#{Prompt.project_name}][#{Prompt.formatted_env}] " \
"#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \
"#{":#{nest_level}" unless nest_level.zero?}#{sep} "
end
]

Pry::Prompt::MAP["rails"] = {
value: RAILS_PROMPT,
description: "Includes the current Rails environment and project folder name.\n" \
"[1] [project_name][Rails.env] pry(main)>"
}
prompts = [
proc { |target_self, nest_level, pry| draw_prompt(target_self, nest_level, pry, '>') },
proc { |target_self, nest_level, pry| draw_prompt(target_self, nest_level, pry, '*') }
]
Pry::Prompt::MAP["rails"] = {value: prompts, description: desc}
end
end