Packages

Framework for automating parts of development and refactoring.

Current section

Files

Jump to
grimoire lib grimoire.ex
Raw

lib/grimoire.ex

defmodule Grimoire do
defp build_content(mod_name) do
"""
defmodule #{mod_name} do
def schema() do
%{}
end
end
"""
end
def new(dir, file_name, mod_name) do
Grimoire.Utilities.Files.latest_file(dir)
|> case do
[] ->
path = Path.join(dir, file_name)
File.write!(path, build_content(mod_name))
f ->
path = Path.join(dir, file_name)
old_content = File.read!(f.full_path)
# Clip off the first line, we're rewriting it
[_hd | tl] = String.split(old_content, "\n")
header = "defmodule #{mod_name} do"
new_content = Enum.join([header | tl], "\n")
File.write!(path, new_content)
end
end
end