Skip to content

Default Plugins #5

@halostatue

Description

@halostatue

It would be nice to have a way to set default plugins for derived variations. I’m trying to make a typedstruct wrapper that also implements Ecto.Type. Something like:

defmodule MyApp.Type do
  defmacro __using__(_) do
    quote do
      use Ecto.Type
      use Typedstruct
      # use TypedStruct, plugins: [MyApp.Typestruct.Plugin.EctoTypes]

      @behaviour MyApp.Type

      @impl Ecto.Type
      def type, do: :map
      # …
    end
  end

  @callback changeset(struct, map) :: Ecto.Changeset.t()
end

Right now, I would need to do:

typedstruct do
  plugin MyApp.Typestruct.Plugin.EctoTypes

  field :code, String.t(), ecto_type: :string
end

With this, I would be able to do:

typedestruct do
  field :code, String.t(), ecto_type: :string
end

I could probably muck around with the block AST by overriding typedstruct/1,2, and I’ll be trying that, but it feels like specifying default plugins for a project like this would be a desirable feature overall.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions