# `AshScylla.ResourceGenerator`
[🔗](https://github.com/ohhi-vn/ash_scylla/blob/main/lib/ash_scylla/resource_generator.ex#L1)

Generates starter Ash Resource modules for AshScylla.

Used by `mix ash_scylla.new_template` to scaffold resource files under
`lib/<app>/resources/<resource>.ex`.

## Arguments

Accepts a resource name (optionally domain-prefixed) and a comma-separated
list of `name:type` attribute pairs.

## Options

- `:domain` — Domain module to include in the generated resource
- `:resource` — Fully-qualified resource module name (overrides positional)

# `parse_args`

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

Parses generator command arguments.

Accepts a resource name (optionally domain-prefixed) and a comma-separated
list of `name:type` attribute pairs.

## Examples

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

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

Options (as keyword list, passed from the Mix task):

  * `:domain` - Domain module to include in the generated resource
  * `:resource` - Fully-qualified resource module name (overrides the
    positional name argument)

# `parse_args`

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

Same as `parse_args/1` but also accepts options from CLI flags.

## Options

  * `:domain` - Domain module to include in the generated resource
  * `:resource` - Fully-qualified resource module name (overrides positional arg)

# `render_create_table`

```elixir
@spec render_create_table(String.t(), [{atom(), atom()}], module()) :: [String.t()]
```

Renders CQL CREATE TABLE and CREATE INDEX statements for a table.

Returns a list of CQL statement strings.

# `render_resource`

```elixir
@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`)
  * `:domain` - Domain module to include via `domain` option in the resource

## Example

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

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

# `resource_file_path`

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

Returns the generated resource file path for a resource name.

# `write_resource`

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

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

## Options

  * `:domain` - Domain module to include in the generated resource
  * `:repo_module` - The repo module to reference

---

*Consult [api-reference.md](api-reference.md) for complete listing*
