Skip to content

Commit

Permalink
* improvement: add data layer introspection to Ash.Resource.Info (#610)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Daniel Stewart <[email protected]>
  • Loading branch information
RaspberryLambda and Dannystu12 authored Jun 10, 2023
1 parent 923bfc7 commit ffaf6d5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ shell.nix
.DS_Store

.vscode
.elixir-tools
2 changes: 1 addition & 1 deletion lib/ash/data_layer/data_layer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ defmodule Ash.DataLayer do
set_tenant: 3

@doc "The data layer of the resource, or nil if it does not have one"
@spec data_layer(Ash.Resource.t() | Spark.Dsl.t()) :: Ash.DataLayer.t()
@spec data_layer(Ash.Resource.t() | Spark.Dsl.t()) :: Ash.DataLayer.t() | nil
def data_layer(resource) do
Extension.get_persisted(resource, :data_layer)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/ash/resource/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,8 @@ defmodule Ash.Resource.Info do
true
end
end

@doc "The data layer of the resource, or nil if it does not have one"
@spec data_layer(Ash.Resource.t()) :: Ash.DataLayer.t() | nil
defdelegate data_layer(resource), to: Ash.DataLayer
end
4 changes: 4 additions & 0 deletions test/resource/info_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,9 @@ defmodule Ash.Test.Resource.InfoTest do
assert false == Info.sortable?(Comment, :post_authors)
assert false == Info.sortable?(Comment, :formatted_post_title, pagination_type: :keyset)
end

test "get datalayer from resource" do
assert Ash.DataLayer.Ets == Info.data_layer(Post)
end
end
end

0 comments on commit ffaf6d5

Please sign in to comment.