Packages
pow_assent
0.2.3
0.4.18
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0
0.1.0-rc.2
0.1.0-rc.1
0.1.0-rc.0
0.1.0-alpha.12
0.1.0-alpha.11
0.1.0-alpha.10
0.1.0-alpha.9
0.1.0-alpha.8
0.1.0-alpha.7
0.1.0-alpha.6
0.1.0-alpha.5
0.1.0-alpha.4
0.1.0-alpha.3
0.1.0-alpha.2
retired
0.1.0-alpha.1
0.1.0-alpha
Multi-provider support for Pow
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/pow_assent/ecto/user_identities/schema/module.ex
defmodule PowAssent.Ecto.UserIdentities.Schema.Module do
@moduledoc """
Generates schema module content.
## Configuration options
* `:binary_id` - if the schema module should use binary id, default nil.
"""
alias PowAssent.Config
@template """
defmodule <%= inspect schema.module %> do
use Ecto.Schema
use PowAssent.Ecto.UserIdentities.Schema, user: <%= inspect(schema.user_module) %>
<%= if schema.binary_id do %>
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id<% end %>
schema <%= inspect schema.table %> do
pow_assent_user_identity_fields()
timestamps(updated_at: false)
end
end
"""
@doc """
Generates schema module file content.
"""
@spec gen(map()) :: binary()
def gen(schema) do
EEx.eval_string(unquote(@template), schema: schema)
end
@doc """
Generates a schema module map.
"""
@spec new(atom(), binary(), binary(), Config.t()) :: map()
def new(context_base, schema_name, schema_plural, config \\ []) do
module = Module.concat([context_base, schema_name])
binary_id = config[:binary_id]
user_module = Module.concat([context_base, "Users.User"])
%{
schema_name: schema_name,
module: module,
table: schema_plural,
binary_id: binary_id,
user_module: user_module
}
end
end