# `StaticContext`
[🔗](https://github.com/exfoundry/static_context/blob/v0.1.0/lib/static_context.ex#L1)

Generates standard data access functions for static lookup modules at compile time.

Static lookup modules hold lists of structs defined in code, not the database —
think lookup tables like states, types, or categories. The `static_context` block
is the table of contents; everything below it is domain logic.

String ids throughout. Matches DB storage, URL params, and form values with no
atom/string boundary to cross.

## Usage

    import StaticContext

    static_context struct: MineState do
      list()
      list_by()
      get()
      get!()
      get_by()
      get_by!()
    end

    def entries do
      [
        %MineState{id: "production",           name: "Production"},
        %MineState{id: "care_and_maintenance", name: "Care and Maintenance"},
        %MineState{id: "closed",               name: "Closed"}
      ]
    end

## Generated functions

| Function    | Signature              | Notes                                      |
|-------------|------------------------|--------------------------------------------|
| `list`      | `list()`               | All entries via `entries/0`                |
| `list_by`   | `list_by(clauses)`     | Enum.filter with clause key validation     |
| `list_for`  | `list_for(assoc, id)`  | Filter by `assoc_id` foreign key           |
| `get`       | `get(id)`              | Binary-only guard, nil if not found        |
| `get!`      | `get!(id)`             | Binary-only guard, raises if not found     |
| `get_by`    | `get_by(clauses)`      | First match or nil                         |
| `get_by!`   | `get_by!(clauses)`     | First match or raises                      |

`get` and `get!` are guarded with `when is_binary(id)`. Passing an atom raises
`FunctionClauseError` — intentional, enforces string ids at the call site.

# `static_context`
*macro* 

Declares the generated functions for a static lookup module.

Accepts a keyword list with `:struct` pointing to the struct module,
and a `do` block containing function declarations like `list()`, `get!()`, `get_by()`.

The calling module must define an `entries/0` function returning a list of structs.

See the module documentation for the full list of supported functions.

---

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