#What is the proper way to include an external non-elixir file into an Elixir project?

6 messages · Page 1 of 1 (latest)

feral lotus
#

I have a file called cluster_schema.cue that I need to use inside a call to System.cmd. Right now I import its location as a module attribute, like so

@schema_location "priv/cluster_schema.cue"

System.cmd("cue", ["vet", file, @schema_location])

My issue is that whenever I modify that file, the changes don't seem to be applied - I tried deleting the build folder, recompiling, etc, nothing seems to work.

What am I missing?

Thanks,
Alex

devout orbit
#

But what exactly you are trying to achieve?

feral lotus
#

I need to run some validations using an external command, and I need to have the contents of that file read by whatever command I am passing to System.cmd

#
  defp validate_file_content(files) do
    for file <- files do
      case System.cmd("cue", ["vet", file, @schema_location], lines: 1024) do
        {"", 0} -> {:ok, file}
        _ -> {:error, "your validation failed"}
      end
    end
  end

This is how my method looks like now

devout orbit
#

At compile time? Why not make that validation part of the Mix task that is ran before compilation?