Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phoenix: Requiring IEx in only :dev and :test for entire project

I'm new to Elixir/Phoenix and I was wondering if there was a way to essentially require IEx for the purpose of IEx.pry in the same manner that in Ruby/Rails you can add something like

group :test, :development do
  gem 'pry', require: 'pry'
end

which would allow you to binding.pry in essentially any file without needing to include require 'pry'

I'm finding that having to require IEx on any controller, model, view, etc I want to debug to be tedious.

like image 264
VitaminMarc Avatar asked Jan 06 '17 20:01

VitaminMarc


People also ask

How do I launch IEX from a Phoenix Project?

Some of the things may be different or may not even work if you are using a different version of IEx. You can launch IEx shell from the command line simply typing iex or if you want to launch a phoenix project by typing iex -S mix phx.server or typing iex -S mix while in a mix based Elixir project.

How do I run tests in Elixir and Phoenix?

To run your tests in an Elixir or Phoenix project in the Elixir Interactive shell run: To run your Phoenix app in the Elixir Interactive shell, you can run: IEx.pry () allows you to set a breakpoint in your code and inspect values.

How do I run IEX from the command line?

You can launch IEx shell from the command line simply typing iex or if you want to launch a phoenix project by typing iex -S mix phx.server or typing iex -S mix while in a mix based Elixir project. Throughout the article, I will show output from real iex session but in most cases output will be truncated and annotated to suit this article.

Do I need a debugger for Elixir and Phoenix?

However, using an actual debugger with a visual interface is much more convenient when you want to view multiple locations, step through the code, and monitor data as your application runs. Setting up the debugger for phoenix or elixir is done automatically for you by Visual Studio Code.


1 Answers

You can use web/web.ex file.

A module that keeps using definitions for controllers, views and so on.

This can be used in your application as:

use App.Web, :controller
use App.Web, :view

The definitions below will be executed for every view, controller, etc, so keep them short and clean, focused on imports, uses and aliases.

Just put require IEx here when you need it for controllers, models etc.

defmodule App.Web do
  def model do
    quote do
      ...
      require IEx
    end
  end
  def controller do
    quote do
      ...
      require IEx
    end
  end
end
like image 138
droptheplot Avatar answered Oct 21 '22 06:10

droptheplot