AshScylla.ResourceGenerator (AshScylla v0.8.0)

Copy Markdown View Source

Generates starter Ash Resource modules for AshScylla.

Summary

Functions

Parses generator command arguments.

Renders an Ash Resource template as a string.

Returns the generated resource file path for a resource name.

Writes a generated resource file to lib/<app>/resources/<resource>.ex.

Functions

parse_args(args)

@spec parse_args([String.t()]) ::
  {:ok, module(), [{atom(), atom()}]} | {:error, String.t()}

Parses generator command arguments.

Example

AshScylla.ResourceGenerator.parse_args([
  "MyResource",
  "user_id:uuid, name:string, age:int"
])

render_resource(resource_name, attributes, opts \\ [])

@spec render_resource(module() | String.t(), [{atom(), atom()}], keyword()) ::
  String.t()

Renders an Ash Resource template as a string.

Options

  • :repo_module - The repo module to reference (defaults to <AppName>.Repo)

Example

AshScylla.ResourceGenerator.render_resource(
  MyApp.User,
  [user_id: :uuid, name: :string, age: :integer],
  repo_module: MyApp.Repo
)

resource_file_path(resource_name)

@spec resource_file_path(module() | String.t()) :: String.t()

Returns the generated resource file path for a resource name.

write_resource(resource_name, attributes)

@spec write_resource(module() | String.t(), [{atom(), atom()}]) :: :ok

Writes a generated resource file to lib/<app>/resources/<resource>.ex.