jkbbwr

jkbbwr

Implicit modules and script style plugins

I want to work on a DSL that looks very similar to unit tests, define some steps but the steps are linked

step "step 1" do
    IO.puts("hi")
end

step "step 2", depends: ["step 1"] do
    IO.puts("bye")
end

Forcing a user to define a module at the top feels possibly distracting.

Two questions, one how should I go about loading an exs at runtime and calling it (I assume Code.compile_file

Second more important question, how might I go about dynamically generating a module or infering one maybe from the filename.

Most Liked

zachdaniel

zachdaniel

Creator of Ash

Dynamically generating modules is easier than you’d expect,

def make_module(stuff) do
  Module.create(derived_module_name(stuff), quote do
    # your module body goes here
  end,
  Macro.Env.location(__ENV__))
end

As for running a .exs file, I think your best bet would be Code.eval_file/2. Also, depending on what you’re looking to do, you may want to look into Reactor: README — reactor v1.0.2, as it may do what you’re looking to do already. And for defining the DSL you may look into Spark: Spark — spark v2.7.2, which is a DSL building toolkit. Still sorely under-documented, but very feature rich. If you’re willing to read the tests to figure out how it works, then you’ll be A-ok. It’s very battle tested.

Last Post!

jkbbwr

jkbbwr

Id probably still have to wrap the content of the .exs file so I might end up using some sort of string eval.

Where Next?

Popular in Questions Top

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
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement