AshScylla.MixHelpers (AshScylla v0.10.0)

Copy Markdown View Source

Shared helper functions for AshScylla Mix tasks.

Provides resource/repo discovery, CLI option handling, and file scanning used by ash_scylla.gen, ash_scylla.migrate, and other tasks.

Summary

Functions

Returns the application name from Mix config.

Checks if a resource module uses AshScylla.DataLayer.

Converts a file path to a module name.

Finds all AshScylla resources via domain config, with file-scan fallback.

Finds and returns the default repo module from AshScylla resources.

Converts a string CLI option value to an atom, if present.

Returns the list of app atoms to scan: the current app + umbrella children.

Discovers Ash domains from the project's app configuration.

Returns the list of lib/ directories to scan (current app + umbrella children).

Scans all .ex files in project lib/ directories for AshScylla resources.

Functions

app_name()

@spec app_name() :: atom()

Returns the application name from Mix config.

ash_scylla_resource?(resource)

@spec ash_scylla_resource?(module()) :: boolean()

Checks if a resource module uses AshScylla.DataLayer.

file_to_module(file)

@spec file_to_module(String.t()) :: atom() | nil

Converts a file path to a module name.

Examples

iex> AshScylla.MixHelpers.file_to_module("lib/my_app/resources/user.ex")
:"Elixir.MyApp.Resources.User"

find_all_resources()

@spec find_all_resources() :: [module()]

Finds all AshScylla resources via domain config, with file-scan fallback.

  1. Reads configured domains from app env
  2. Gets each domain's resources via Ash.Domain.Info.resources/1
  3. Filters to AshScylla resources
  4. Falls back to scanning lib/**/*.ex files if no domains configured

find_default_repo()

@spec find_default_repo() :: module()

Finds and returns the default repo module from AshScylla resources.

Extracts the repo from each resource's DSL config and returns the first one.

maybe_atomize(opts, key)

@spec maybe_atomize(
  keyword(),
  atom()
) :: keyword()

Converts a string CLI option value to an atom, if present.

project_apps()

@spec project_apps() :: [atom()]

Returns the list of app atoms to scan: the current app + umbrella children.

project_domains()

@spec project_domains() :: [module()]

Discovers Ash domains from the project's app configuration.

Checks each app for :ash_domains config and ensures modules are compiled.

project_lib_paths()

@spec project_lib_paths() :: [String.t()]

Returns the list of lib/ directories to scan (current app + umbrella children).

scan_files_for_resources()

@spec scan_files_for_resources() :: [module()]

Scans all .ex files in project lib/ directories for AshScylla resources.