GuardedStruct.AshResource.Info (GuardedStruct v0.1.0-beta.1)

Copy Markdown View Source

Runtime introspection for the GuardedStruct.AshResource extension.

Same shape as GuardedStruct.Info but reads from the __guarded_* namespaced functions the Ash extension generates (so it doesn't collide with Ash's own Ash.Resource.Info callbacks).

Example

defmodule MyApp.User do
  use Ash.Resource,
    domain: MyApp.MyDomain,
    extensions: [GuardedStruct.AshResource]

  guardedstruct do
    field :nickname, :string, derives: "validate(string, max_len=20)"
  end
end

GuardedStruct.AshResource.Info.fields(MyApp.User)
#=> [:nickname]

GuardedStruct.AshResource.Info.field(MyApp.User, :nickname)
#=> %{kind: :field, name: :nickname, derives: "validate(string, max_len=20)", ...}

Summary

Functions

Return metadata for a single field name, or nil.

True if a guardedstruct-declared field exists with this name.

Return field, sub_field, and conditional_field names in declaration order.

Return the runtime field metadata stored under __guarded_fields__/0.

guardedstruct DSL entities

Only effective inside the GuardedStruct.AshResource extension. When true, injects GuardedStruct.AshResource.Change into the resource's top-level changes section so every :create and :update action automatically runs the GuardedStruct pipeline. Equivalent to writing changes do change GuardedStruct.AshResource.Change end by hand. No-op outside the Ash extension.

Only effective inside the GuardedStruct.AshResource extension. When true, injects GuardedStruct.AshResource.Change into the resource's top-level changes section so every :create and :update action automatically runs the GuardedStruct pipeline. Equivalent to writing changes do change GuardedStruct.AshResource.Change end by hand. No-op outside the Ash extension.

When true, derives a JSON encoder. Uses Jason.Encoder if :jason is in the user's deps; otherwise falls back to the built-in JSON.Encoder on Elixir 1.18+. No-op if neither is available.

When true, derives a JSON encoder. Uses Jason.Encoder if :jason is in the user's deps; otherwise falls back to the built-in JSON.Encoder on Elixir 1.18+. No-op if neither is available.

guardedstruct DSL options

Return the full information map (path, keys, enforce_keys, options, etc.).

Run the validation pipeline on attrs and return {:ok, validated_map} or {:error, errors}. Convenience wrapper over the resource's own __guarded_change__/1.

Functions

field(module, name)

Return metadata for a single field name, or nil.

field?(module, name)

True if a guardedstruct-declared field exists with this name.

fields(module)

Return field, sub_field, and conditional_field names in declaration order.

fields_meta(module)

Return the runtime field metadata stored under __guarded_fields__/0.

guardedstruct(dsl_or_extended)

@spec guardedstruct(dsl_or_extended :: module() | map()) :: [struct()]

guardedstruct DSL entities

guardedstruct_auto_wire(dsl_or_extended)

@spec guardedstruct_auto_wire(dsl_or_extended :: module() | map()) ::
  {:ok, boolean()} | :error

Only effective inside the GuardedStruct.AshResource extension. When true, injects GuardedStruct.AshResource.Change into the resource's top-level changes section so every :create and :update action automatically runs the GuardedStruct pipeline. Equivalent to writing changes do change GuardedStruct.AshResource.Change end by hand. No-op outside the Ash extension.

guardedstruct_auto_wire!(dsl_or_extended)

@spec guardedstruct_auto_wire!(dsl_or_extended :: module() | map()) ::
  boolean() | no_return()

Only effective inside the GuardedStruct.AshResource extension. When true, injects GuardedStruct.AshResource.Change into the resource's top-level changes section so every :create and :update action automatically runs the GuardedStruct pipeline. Equivalent to writing changes do change GuardedStruct.AshResource.Change end by hand. No-op outside the Ash extension.

guardedstruct_json(dsl_or_extended)

@spec guardedstruct_json(dsl_or_extended :: module() | map()) ::
  {:ok, boolean()} | :error

When true, derives a JSON encoder. Uses Jason.Encoder if :jason is in the user's deps; otherwise falls back to the built-in JSON.Encoder on Elixir 1.18+. No-op if neither is available.

guardedstruct_json!(dsl_or_extended)

@spec guardedstruct_json!(dsl_or_extended :: module() | map()) ::
  boolean() | no_return()

When true, derives a JSON encoder. Uses Jason.Encoder if :jason is in the user's deps; otherwise falls back to the built-in JSON.Encoder on Elixir 1.18+. No-op if neither is available.

guardedstruct_options(dsl_or_extended)

@spec guardedstruct_options(dsl_or_extended :: module() | map()) :: %{
  required(atom()) => any()
}

guardedstruct DSL options

Returns a map containing the and any configured or default values.

information(module)

Return the full information map (path, keys, enforce_keys, options, etc.).

validate(module, attrs, error? \\ false)

Run the validation pipeline on attrs and return {:ok, validated_map} or {:error, errors}. Convenience wrapper over the resource's own __guarded_change__/1.