csadewa

csadewa

Tools/tips for easily change a module/function namespace

Hi, i am currently in the middle of refactoring effort, and part of that effort was changing file/schema/module namespace into a more proper namespace, for example changing a module from LoadService.V2.Loads.Schema.JobPreassignedTransporterCompanyData to LoadService.V2.DeliveryOrderManagement.Schema.JobPreassignedTransporterCompanyData.

I found a lot of difficulties in trying to find out which file / module that call LoadService.V2.Loads.Schema.JobPreassignedTransporterCompanyData previously, especially because there is a lot of way to alias a module and call it in Elixir, for example:

  1. direct call (easiest to find):
LoadService.V2.Loads.Schema.JobPreassignedTransporterCompanyData.some_function
  1. alias direct module:
alias LoadService.V2.Loads.Schema.JobPreassignedTransporterCompanyData
JobPreassignedTransporterCompanyData.some_function
  1. alias parent module
alias LoadService.V2.Loads.Schema
Schema.JobPreassignedTransporterCompanyData.some_function

What better ways i could do to make this process of finding & renaming module namespace better?

Most Liked

csadewa

csadewa

Oh, turn out warning emitted by compiler is useful for catching when refactoring namespace if there’s any missed rename. i currently would

mix clean
mix test &> mix_test_result.txt
# wait a bit + check mix_test_result.txt periodically to ensure all code + test code get compiled, but skip actual testing execution to get compiler warning

if i miss some renaming, it would show up in mix_test_result.txt like

warning: LoadService.V2.DeliveryOrderManagement.Schema.JobPreassignedTransporterCompanyData.btms_send_transporter_exclusive_shipment_notifications/2 is undefined or private
lib/load_service/v2/loads/api/delivery_order.ex:2614: LoadService.V2.Loads.API.DeliveryOrder.save_delivery_order/3

csadewa

csadewa

A bit of update, turn out that mix has a functionality for tracking caller of a particular module via xref, it can be used to note which file that need to be changed, though it does require full recompilation of code from every invocation, like

mix xref callers LoadService.V2.Loads.JobPreassignedTransporterCompanyData
(…recompile whole application)
lib/load_service/v2/delivery_order_management/jobs.ex (runtime)
lib/load_service/v2/loads/api/delivery_order.ex (runtime)
lib/load_service/v2/oban/job.ex (runtime)

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement