Skip to content

Commit 6dc59a2

Browse files
committed
Group callbacks for better comprehension
1 parent a92285a commit 6dc59a2

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

lib/ecto/repo.ex

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ defmodule Ecto.Repo do
416416
application environment. It must return `{:ok, keyword}` with the updated
417417
list of configuration or `:ignore` (only in the `:supervisor` case).
418418
"""
419+
@doc group: "User callbacks"
419420
@callback init(context :: :supervisor | :runtime, config :: Keyword.t()) ::
420421
{:ok, Keyword.t()} | :ignore
421422

@@ -424,6 +425,7 @@ defmodule Ecto.Repo do
424425
@doc """
425426
Returns the adapter tied to the repository.
426427
"""
428+
@doc group: "Runtime API"
427429
@callback __adapter__ :: Ecto.Adapter.t()
428430

429431
@doc """
@@ -432,6 +434,7 @@ defmodule Ecto.Repo do
432434
If the `c:init/2` callback is implemented in the repository,
433435
it will be invoked with the first argument set to `:runtime`.
434436
"""
437+
@doc group: "Runtime API"
435438
@callback config() :: Keyword.t()
436439

437440
@doc """
@@ -446,6 +449,7 @@ defmodule Ecto.Repo do
446449
See the configuration in the moduledoc for options shared between adapters,
447450
for adapter-specific configuration see the adapter's documentation.
448451
"""
452+
@doc group: "Runtime API"
449453
@callback start_link(opts :: Keyword.t()) ::
450454
{:ok, pid}
451455
| {:error, {:already_started, pid}}
@@ -454,6 +458,7 @@ defmodule Ecto.Repo do
454458
@doc """
455459
Shuts down the repository.
456460
"""
461+
@doc group: "Runtime API"
457462
@callback stop(timeout) :: :ok
458463

459464
@doc """
@@ -474,6 +479,7 @@ defmodule Ecto.Repo do
474479
See the ["Shared options"](#module-shared-options) section at the module
475480
documentation for more options.
476481
"""
482+
@doc group: "Transaction API"
477483
@callback checkout((() -> result), opts :: Keyword.t()) :: result when result: var
478484

479485
@doc """
@@ -496,14 +502,15 @@ defmodule Ecto.Repo do
496502
end)
497503
498504
"""
505+
@doc group: "Transaction API"
499506
@callback checked_out?() :: boolean
500507

501508
@doc """
502-
Loads `data` into a struct or a map.
509+
Loads `data` into a schema or a map.
503510
504-
The first argument can be a a schema module, or a
505-
map (of types) and determines the return value:
506-
a struct or a map, respectively.
511+
The first argument can be a a schema module or a map (of types).
512+
The first argument determines the return value: a struct or a map,
513+
respectively.
507514
508515
The second argument `data` specifies fields and values that are to be loaded.
509516
It can be a map, a keyword list, or a `{fields, values}` tuple.
@@ -540,8 +547,9 @@ defmodule Ecto.Repo do
540547
[%User{...}, ...]
541548
542549
"""
550+
@doc group: "Schema API"
543551
@callback load(
544-
module_or_map :: module | map(),
552+
schema_or_map :: module | map(),
545553
data :: map() | Keyword.t() | {list, list}
546554
) :: Ecto.Schema.t() | map()
547555

@@ -550,6 +558,7 @@ defmodule Ecto.Repo do
550558
551559
See `c:put_dynamic_repo/1` for more information.
552560
"""
561+
@doc group: "Runtime API"
553562
@callback get_dynamic_repo() :: atom() | pid()
554563

555564
@doc """
@@ -585,6 +594,7 @@ defmodule Ecto.Repo do
585594
**Note this feature is experimental and may be changed or removed in future
586595
releases.**
587596
"""
597+
@doc group: "Runtime API"
588598
@callback put_dynamic_repo(name_or_pid :: atom() | pid()) :: atom() | pid()
589599

590600
## Ecto.Adapter.Queryable
@@ -619,6 +629,7 @@ defmodule Ecto.Repo do
619629
MyRepo.get(Post, 42, prefix: "public")
620630
621631
"""
632+
@doc group: "Query API"
622633
@callback get(queryable :: Ecto.Queryable.t(), id :: term, opts :: Keyword.t()) ::
623634
Ecto.Schema.t() | nil
624635

@@ -644,6 +655,7 @@ defmodule Ecto.Repo do
644655
MyRepo.get!(Post, 42, prefix: "public")
645656
646657
"""
658+
@doc group: "Query API"
647659
@callback get!(queryable :: Ecto.Queryable.t(), id :: term, opts :: Keyword.t()) ::
648660
Ecto.Schema.t()
649661

@@ -671,6 +683,7 @@ defmodule Ecto.Repo do
671683
MyRepo.get_by(Post, [title: "My post"], prefix: "public")
672684
673685
"""
686+
@doc group: "Query API"
674687
@callback get_by(
675688
queryable :: Ecto.Queryable.t(),
676689
clauses :: Keyword.t() | map,
@@ -702,6 +715,7 @@ defmodule Ecto.Repo do
702715
MyRepo.get_by!(Post, [title: "My post"], prefix: "public")
703716
704717
"""
718+
@doc group: "Query API"
705719
@callback get_by!(
706720
queryable :: Ecto.Queryable.t(),
707721
clauses :: Keyword.t() | map,
@@ -726,6 +740,7 @@ defmodule Ecto.Repo do
726740
MyRepo.reload([deleted_post, post1])
727741
[nil, %Post{}]
728742
"""
743+
@doc group: "Schema API"
729744
@callback reload(
730745
struct_or_structs :: Ecto.Schema.t() | [Ecto.Schema.t()],
731746
opts :: Keyword.t()
@@ -744,6 +759,7 @@ defmodule Ecto.Repo do
744759
MyRepo.reload!([post1, post2])
745760
[%Post{}, %Post{}]
746761
"""
762+
@doc group: "Schema API"
747763
@callback reload!(struct_or_structs, opts :: Keyword.t()) :: struct_or_structs
748764
when struct_or_structs: Ecto.Schema.t() | [Ecto.Schema.t()]
749765

@@ -781,6 +797,7 @@ defmodule Ecto.Repo do
781797
Repo.aggregate(Post, :count, prefix: "private")
782798
783799
"""
800+
@doc group: "Query API"
784801
@callback aggregate(
785802
queryable :: Ecto.Queryable.t(),
786803
aggregate :: :count,
@@ -805,6 +822,7 @@ defmodule Ecto.Repo do
805822
query = from Post, limit: 10
806823
Repo.aggregate(query, :avg, :visits)
807824
"""
825+
@doc group: "Query API"
808826
@callback aggregate(
809827
queryable :: Ecto.Queryable.t(),
810828
aggregate :: :avg | :count | :max | :min | :sum,
@@ -842,6 +860,7 @@ defmodule Ecto.Repo do
842860
query = from p in Post, where: p.like_count > 10
843861
Repo.exists?(query)
844862
"""
863+
@doc group: "Query API"
845864
@callback exists?(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) :: boolean()
846865

847866
@doc """
@@ -868,6 +887,7 @@ defmodule Ecto.Repo do
868887
query = from p in Post, join: c in assoc(p, :comments), where: p.id == ^post_id
869888
Repo.one(query, prefix: "private")
870889
"""
890+
@doc group: "Query API"
871891
@callback one(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) ::
872892
Ecto.Schema.t() | nil
873893

@@ -888,6 +908,7 @@ defmodule Ecto.Repo do
888908
See the ["Shared options"](#module-shared-options) section at the module
889909
documentation for more options.
890910
"""
911+
@doc group: "Query API"
891912
@callback one!(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) ::
892913
Ecto.Schema.t()
893914

@@ -936,6 +957,7 @@ defmodule Ecto.Repo do
936957
937958
The query given to preload may also preload its own associations.
938959
"""
960+
@doc group: "Schema API"
939961
@callback preload(structs_or_struct_or_nil, preloads :: term, opts :: Keyword.t()) ::
940962
structs_or_struct_or_nil
941963
when structs_or_struct_or_nil: [Ecto.Schema.t()] | Ecto.Schema.t() | nil
@@ -975,6 +997,7 @@ defmodule Ecto.Repo do
975997
made from associations and preloads. It is not invoked for each
976998
individual join inside a query.
977999
"""
1000+
@doc group: "User callbacks"
9781001
@callback prepare_query(operation, query :: Ecto.Query.t(), opts :: Keyword.t()) ::
9791002
{Ecto.Query.t(), Keyword.t()}
9801003
when operation: :all | :update_all | :delete_all | :stream | :insert_all
@@ -993,6 +1016,7 @@ defmodule Ecto.Repo do
9931016
this callback will be invoked once at the beginning, but the
9941017
options returned here will be passed to all following operations.
9951018
"""
1019+
@doc group: "User callbacks"
9961020
@callback default_options(operation) :: Keyword.t()
9971021
when operation: :all | :insert_all | :update_all | :delete_all | :stream |
9981022
:transaction | :insert | :update | :delete | :insert_or_update
@@ -1021,6 +1045,7 @@ defmodule Ecto.Repo do
10211045
select: p.title
10221046
MyRepo.all(query)
10231047
"""
1048+
@doc group: "Query API"
10241049
@callback all(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) :: [Ecto.Schema.t()]
10251050

10261051
@doc """
@@ -1057,6 +1082,7 @@ defmodule Ecto.Repo do
10571082
Enum.to_list(stream)
10581083
end)
10591084
"""
1085+
@doc group: "Query API"
10601086
@callback stream(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) :: Enum.t()
10611087

10621088
@doc """
@@ -1101,6 +1127,7 @@ defmodule Ecto.Repo do
11011127
|> MyRepo.update_all([])
11021128
11031129
"""
1130+
@doc group: "Query API"
11041131
@callback update_all(
11051132
queryable :: Ecto.Queryable.t(),
11061133
updates :: Keyword.t(),
@@ -1130,6 +1157,7 @@ defmodule Ecto.Repo do
11301157
11311158
from(p in Post, where: p.id < 10) |> MyRepo.delete_all
11321159
"""
1160+
@doc group: "Query API"
11331161
@callback delete_all(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) ::
11341162
{integer, nil | [term]}
11351163

@@ -1303,6 +1331,7 @@ defmodule Ecto.Repo do
13031331
so they are not currently compatible with MySQL
13041332
13051333
"""
1334+
@doc group: "Schema API"
13061335
@callback insert_all(
13071336
schema_or_source :: binary | {binary, module} | module,
13081337
entries_or_query :: [map | [{atom, term | Ecto.Query.t}]] | Ecto.Query.t,
@@ -1474,6 +1503,7 @@ defmodule Ecto.Repo do
14741503
at the same time is not recommended, as Ecto will be unable to actually
14751504
track the proper status of the association.
14761505
"""
1506+
@doc group: "Schema API"
14771507
@callback insert(
14781508
struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t(),
14791509
opts :: Keyword.t()
@@ -1535,6 +1565,7 @@ defmodule Ecto.Repo do
15351565
{:error, changeset} -> # Something went wrong
15361566
end
15371567
"""
1568+
@doc group: "Schema API"
15381569
@callback update(changeset :: Ecto.Changeset.t(), opts :: Keyword.t()) ::
15391570
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
15401571

@@ -1585,6 +1616,7 @@ defmodule Ecto.Repo do
15851616
{:error, changeset} -> # Something went wrong
15861617
end
15871618
"""
1619+
@doc group: "Schema API"
15881620
@callback insert_or_update(changeset :: Ecto.Changeset.t(), opts :: Keyword.t()) ::
15891621
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
15901622

@@ -1626,6 +1658,7 @@ defmodule Ecto.Repo do
16261658
end
16271659
16281660
"""
1661+
@doc group: "Schema API"
16291662
@callback delete(
16301663
struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t(),
16311664
opts :: Keyword.t()
@@ -1634,6 +1667,7 @@ defmodule Ecto.Repo do
16341667
@doc """
16351668
Same as `c:insert/2` but returns the struct or raises if the changeset is invalid.
16361669
"""
1670+
@doc group: "Schema API"
16371671
@callback insert!(
16381672
struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t(),
16391673
opts :: Keyword.t()
@@ -1642,19 +1676,22 @@ defmodule Ecto.Repo do
16421676
@doc """
16431677
Same as `c:update/2` but returns the struct or raises if the changeset is invalid.
16441678
"""
1679+
@doc group: "Schema API"
16451680
@callback update!(changeset :: Ecto.Changeset.t(), opts :: Keyword.t()) ::
16461681
Ecto.Schema.t()
16471682

16481683
@doc """
16491684
Same as `c:insert_or_update/2` but returns the struct or raises if the changeset
16501685
is invalid.
16511686
"""
1687+
@doc group: "Schema API"
16521688
@callback insert_or_update!(changeset :: Ecto.Changeset.t(), opts :: Keyword.t()) ::
16531689
Ecto.Schema.t()
16541690

16551691
@doc """
16561692
Same as `c:delete/2` but returns the struct or raises if the changeset is invalid.
16571693
"""
1694+
@doc group: "Schema API"
16581695
@callback delete!(
16591696
struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t(),
16601697
opts :: Keyword.t()
@@ -1735,6 +1772,7 @@ defmodule Ecto.Repo do
17351772
|> MyRepo.transaction
17361773
17371774
"""
1775+
@doc group: "Transaction API"
17381776
@callback transaction(fun_or_multi :: fun | Ecto.Multi.t(), opts :: Keyword.t()) ::
17391777
{:ok, any}
17401778
| {:error, any}
@@ -1762,6 +1800,7 @@ defmodule Ecto.Repo do
17621800
end)
17631801
17641802
"""
1803+
@doc group: "Transaction API"
17651804
@callback in_transaction?() :: boolean
17661805

17671806
@doc """
@@ -1771,5 +1810,6 @@ defmodule Ecto.Repo do
17711810
17721811
Note that calling `rollback` causes the code in the transaction to stop executing.
17731812
"""
1813+
@doc group: "Transaction API"
17741814
@callback rollback(value :: any) :: no_return
17751815
end

mix.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ defmodule Ecto.MixProject do
6161
skip_undefined_reference_warnings_on: ["CHANGELOG.md"],
6262
extras: extras(),
6363
groups_for_extras: groups_for_extras(),
64+
groups_for_functions: [
65+
group_for_function("Query API"),
66+
group_for_function("Schema API"),
67+
group_for_function("Transaction API"),
68+
group_for_function("Runtime API"),
69+
group_for_function("User callbacks")
70+
],
6471
groups_for_modules: [
6572
# Ecto,
6673
# Ecto.Changeset,
@@ -122,6 +129,8 @@ defmodule Ecto.MixProject do
122129
]
123130
end
124131

132+
defp group_for_function(group), do: {String.to_atom(group), &(&1[:group] == group)}
133+
125134
defp groups_for_extras do
126135
[
127136
"Introduction": ~r/guides\/introduction\/.?/,

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%{
22
"decimal": {:hex, :decimal, "1.6.0", "bfd84d90ff966e1f5d4370bdd3943432d8f65f07d3bab48001aebd7030590dcc", [:mix], [], "hexpm", "bbd124e240e3ff40f407d50fced3736049e72a73d547f69201484d3a624ab569"},
33
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"},
4-
"ex_doc": {:hex, :ex_doc, "0.25.1", "4b736fa38dc76488a937e5ef2944f5474f3eff921de771b25371345a8dc810bc", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3200b0a69ddb2028365281fbef3753ea9e728683863d8cdaa96580925c891f67"},
4+
"ex_doc": {:hex, :ex_doc, "0.25.2", "4f1cae793c4d132e06674b282f1d9ea3bf409bcca027ddb2fe177c4eed6a253f", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5b0c172e87ac27f14dfd152d52a145238ec71a95efbf29849550278c58a393d6"},
55
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b96c400e04b7b765c0854c05a4966323e90c0d11fee0483b1567cda079abb205"},
66
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
77
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},

0 commit comments

Comments
 (0)