Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow {module, function, args} for mixin #37

Merged
merged 3 commits into from
Mar 1, 2024

Conversation

jechol
Copy link
Contributor

@jechol jechol commented Feb 29, 2024

Contributor checklist

  • Bug fixes include regression tests
  • Features include unit/acceptance tests

@rgraff
Copy link
Contributor

rgraff commented Feb 29, 2024

@jechol what's the use case here as opposed to just have a module mixin? Can you update the getting started guide with an example?

@jechol
Copy link
Contributor Author

jechol commented Mar 1, 2024

My use case is that I want to mix-in AshAdmin's admin section with name and resource group.

defmodule Foo do
  use Ash.Resource, extensions: [AshPaperTrail.Resource]

  paper_trail do
    mixin {MyPaperTrailMixin, :mixin, ["foo", :foobar]}
  end
end

defmodule Bar do
  use Ash.Resource, extensions: [AshPaperTrail.Resource]

  paper_trail do
    mixin {MyPaperTrailMixin, :mixin, ["bar", :foobar]}
  end
end


defmodule MyPaperTrailMixin do
  def mixin(name, group) do
    quote do
      admin do
        name unquote(name)
        resource_group unquote(group)
      end
    end
  end
end

@jechol
Copy link
Contributor Author

jechol commented Mar 1, 2024

@rgraff I updated the guide to use the {module, function, args} format, because it provides more flexibility than the use syntax.

@rgraff
Copy link
Contributor

rgraff commented Mar 1, 2024

@jechol Looks good. Thank you for your contribution. 🎉

@rgraff rgraff merged commit c422954 into ash-project:main Mar 1, 2024
13 checks passed
@jechol jechol deleted the mfa-mixin branch March 3, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants