Skip to content

Commit

Permalink
Merge pull request nebulab#4 from vassalloandrea/vassalloandrea/suppo…
Browse files Browse the repository at this point in the history
…rt-rails-6

Use the new Pry APIs
  • Loading branch information
vassalloandrea authored Jun 15, 2021
2 parents 438136d + 0ce2a7f commit f6d3cbe
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/dev_tools/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
require 'pry-byebug'
require 'awesome_print'

if Rails.env.development?
require 'letter_opener'
end

if Rails.env.development? || Rails.env.test?
require 'dotenv-rails'
end
require 'letter_opener' if Rails.env.development?
require 'dotenv-rails' if Rails.env.development? || Rails.env.test?

AwesomePrint.pry!

module DevTools
class Railtie < Rails::Railtie
config.action_mailer.delivery_method = :letter_opener if Rails.env.development?

initializer 'dev_tools.initialize' do |app|
initializer 'dev_tools.initialize' do
Pry.config.should_load_rc = false

parent_name = if Rails::VERSION::MAJOR >= 6
Expand All @@ -27,16 +22,15 @@ class Railtie < Rails::Railtie
Rails.application.class.parent_name
end

Pry.config.prompt_name = "\001\e[1;32m\002#{parent_name.downcase}\001\e[0m\002/\001\e[1;31m\002#{Rails.env.downcase}"

Pry.prompt = [
proc { |target_self, nest_level, pry|
"[#{pry.input_array.size}] #{Pry.config.prompt_name} \001\e[0m\002(\001\e[0;33m\002#{Pry.view_clip(target_self)}\001\e[0m\002) #{":#{nest_level}" unless nest_level.zero?}> "
},
proc { |target_self, nest_level, pry|
"[#{pry.input_array.size}] #{Pry.config.prompt_name} \001\e[0m\002(\001\e[0;33m\002#{Pry.view_clip(target_self)}\001\e[0m\002) #{":#{nest_level}" unless nest_level.zero?}< "
}
]
Pry::Prompt.add(
"\001\e[1;32m\002#{parent_name.downcase}\001\e[0m\002/\001\e[1;31m\002#{Rails.env.downcase}",
'Includes the current Rails environment.',
%w[> <]
) do |target_self, nest_level, pry, sep|
"[#{pry.input_array.size}] " \
"#{Pry.config.prompt_name} \001\e[0m\002(\001\e[0;33m\002#{Pry.view_clip(target_self)}" \
"\001\e[0m\002) #{":#{nest_level}" unless nest_level.zero?}#{sep} "
end
end
end
end

0 comments on commit f6d3cbe

Please sign in to comment.