Skip to content

Commit

Permalink
add support for Rails prompt on Pry v0.12+
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Nov 6, 2018
1 parent 6794e33 commit a20b297
Showing 1 changed file with 20 additions and 18 deletions.
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

0 comments on commit a20b297

Please sign in to comment.