Skip to content

Commit

Permalink
docs: work on docs coverage & update ex_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 27, 2025
1 parent 0ce7feb commit 7f867e5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
4 changes: 0 additions & 4 deletions lib/ash/type/keyword.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ defmodule Ash.Type.Keyword do
]
]

def field_types(value) do
{:ok, value}
end

@moduledoc """
Represents a keyword list, stored as a `:map` in the database.
Expand Down
4 changes: 0 additions & 4 deletions lib/ash/type/map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ defmodule Ash.Type.Map do
]
]

def field_types(value) do
{:ok, value}
end

@moduledoc """
Represents a map stored in the database.
Expand Down
7 changes: 1 addition & 6 deletions lib/ash/type/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ defmodule Ash.Type.String do
end
end

@impl true
def apply_constraints(nil, _), do: :ok

def apply_constraints(value, constraints) do
Expand Down Expand Up @@ -281,10 +282,4 @@ defmodule Ash.Type.String do
def dump_to_native(value, _) do
Ecto.Type.dump(:string, value)
end

def match(%Regex{} = regex), do: {:ok, regex}

def match(_) do
{:error, "Must provide a regex to match, e.g ~r/foobar/"}
end
end
4 changes: 0 additions & 4 deletions lib/ash/type/struct.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ defmodule Ash.Type.Struct do
#{Spark.Options.docs(@constraints)}
"""

def field_types(value) do
{:ok, value}
end

use Ash.Type

@impl true
Expand Down
32 changes: 32 additions & 0 deletions lib/ash/type/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,11 @@ defmodule Ash.Type do
type.dump_to_native(term, constraints)
end

@doc """
Modifies an expression to apply a type's casting logic to the value it produces.
This delegates to the underlying types implementaiton of `c:cast_atomic/2`.
"""
@spec cast_atomic(t(), term, constraints()) ::
{:atomic, Ash.Expr.t()}
| {:ok, term}
Expand Down Expand Up @@ -1280,6 +1285,11 @@ defmodule Ash.Type do
end
end

@doc """
Applies a types constraints to an expression.
This delegates to the underlying types implementaiton of `c:apply_atomic_constraints/2`.
"""
@spec apply_atomic_constraints(t(), term, constraints()) ::
{:ok, Ash.Expr.t()} | {:error, Ash.Error.t()}
def apply_atomic_constraints({:array, {:array, _}}, _term, _constraints),
Expand Down Expand Up @@ -1349,6 +1359,11 @@ defmodule Ash.Type do
type.equal?(left, right)
end

@doc """
Provides the changeset, action_input or query to the type, to potentially store in its constraints.
This is used for embedded types to allow accessing the parent changeset in certain cases.
"""
@spec include_source(
t(),
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
Expand All @@ -1367,6 +1382,11 @@ defmodule Ash.Type do
type.include_source(constraints, changeset_or_query)
end

@doc """
Merges two load statements for a given type.
This is used to "load through" types. For more see `load/5`.
"""
@spec merge_load(
type :: Ash.Type.t(),
left :: term(),
Expand All @@ -1390,6 +1410,11 @@ defmodule Ash.Type do
type.merge_load(left, right, constraints, context)
end

@doc """
Checks if a given path has been loaded on a type.
This is used to "load through" types. For more see `load/5`.
"""
@spec loaded?(
type :: Ash.Type.t(),
value_or_values :: term,
Expand Down Expand Up @@ -1418,6 +1443,13 @@ defmodule Ash.Type do
type.loaded?(value, load_path, constraints, opts)
end

@doc """
Apply a load statement to a value.
This is used for types that can be "loaded through". For example, maps, unions and structs.
If they have keys that are embedded types, for example, we want to be able to apply a load
statements to their contents.
"""
@spec load(
type :: Ash.Type.t(),
values :: list(term),
Expand Down
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ defmodule Ash.MixProject do

# Dev/Test dependencies
{:eflame, "~> 1.0", only: [:dev, :test]},
# {:ex_doc, "~> 0.32", only: [:dev, :test], runtime: false},
{:ex_doc, github: "elixir-lang/ex_doc", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.37-rc", only: [:dev, :test], runtime: false},
{:ex_check, "~> 0.12", only: [:dev, :test]},
{:credo, ">= 0.0.0", only: [:dev, :test], runtime: false},
{:dialyxir, ">= 0.0.0", only: [:dev, :test], runtime: false},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
"ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"},
"ex_check": {:hex, :ex_check, "0.16.0", "07615bef493c5b8d12d5119de3914274277299c6483989e52b0f6b8358a26b5f", [:mix], [], "hexpm", "4d809b72a18d405514dda4809257d8e665ae7cf37a7aee3be6b74a34dec310f5"},
"ex_doc": {:git, "https://github.com/elixir-lang/ex_doc.git", "51cd42207f193d34172de79c8896985c787bfa38", []},
"ex_doc": {:hex, :ex_doc, "0.37.0-rc.0", "cf3b582b8410052a2ce92e181b4f92e6fe1e4d77e0c966715a112de189667cd6", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "32aa9e539f23aafd6bec490ec84d0bfc10ab9086561239aaf4aa8559f3ba559c"},
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
"finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"},
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},
Expand Down

0 comments on commit 7f867e5

Please sign in to comment.