Module: RailsEnvSwitcher::Pry

Defined in:
lib/rails-env-switcher/pry.rb

Class Method Summary collapse

Class Method Details

.setupObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails-env-switcher/pry.rb', line 2

def self.setup
  ::Pry::CommandSet.new do
    create_command "env", "Switch environment. ctrl+d to leave" do
      group "Environment"
      def process(env)
        unless env
          puts "Usage: 'env test' for example"
        end

        RailsEnvSwitcher.with_env(env) do
          # irb-config compatibility
          if defined?(::IRB::Pry::TopLevel)
            TopLevel.new.pry
          else
            env.pry
          end
        end
      end
    end
  end.tap { |cmd| ::Pry::Commands.import cmd }
end