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
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
Id probably still have to wrap the content of the .exs file so I might end up using some sort of string eval.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









