Skip to content

Commit 804000c

Browse files
committed
1 parent 4187529 commit 804000c

File tree

74 files changed

+1886
-834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1886
-834
lines changed

config/config.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Config
22

3-
if Mix.env == :test do
3+
if Mix.env() == :test do
44
import_config "test.exs"
55
end

lib/mix/pow_assent.ex

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@ defmodule Mix.PowAssent do
88
def validate_schema_args!([schema, plural | _rest] = args, task) do
99
cond do
1010
not schema_valid?(schema) ->
11-
raise_invalid_schema_args_error!("Expected the schema argument, #{inspect schema}, to be a valid module name", task)
11+
raise_invalid_schema_args_error!(
12+
"Expected the schema argument, #{inspect(schema)}, to be a valid module name",
13+
task
14+
)
15+
1216
not plural_valid?(plural) ->
13-
raise_invalid_schema_args_error!("Expected the plural argument, #{inspect plural}, to be all lowercase using snake_case convention", task)
17+
raise_invalid_schema_args_error!(
18+
"Expected the plural argument, #{inspect(plural)}, to be all lowercase using snake_case convention",
19+
task
20+
)
21+
1422
true ->
1523
schema_options_from_args(args)
1624
end
1725
end
26+
1827
def validate_schema_args!([_schema | _rest], task) do
1928
raise_invalid_schema_args_error!("Invalid arguments", task)
2029
end
30+
2131
def validate_schema_args!([], _task), do: schema_options_from_args()
2232

2333
defp schema_valid?(schema), do: schema =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/
@@ -35,6 +45,10 @@ defmodule Mix.PowAssent do
3545
end
3646

3747
defp schema_options_from_args(_opts \\ [])
38-
defp schema_options_from_args([schema, plural | _rest]), do: %{schema_name: schema, schema_plural: plural}
39-
defp schema_options_from_args(_any), do: %{schema_name: "UserIdentities.UserIdentity", schema_plural: "user_identities"}
48+
49+
defp schema_options_from_args([schema, plural | _rest]),
50+
do: %{schema_name: schema, schema_plural: plural}
51+
52+
defp schema_options_from_args(_any),
53+
do: %{schema_name: "UserIdentities.UserIdentity", schema_plural: "user_identities"}
4054
end

lib/mix/tasks/ecto/pow_assent.ecto.gen.migration.ex

+16-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,22 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do
5050
|> Enum.each(&create_migration_file/1)
5151
end
5252

53-
defp create_migration_file(%{repo: repo, binary_id: binary_id, users_table: users_table, schema_plural: schema_plural}) do
54-
context_base = Pow.app_base(Pow.otp_app())
55-
schema = UserIdentitiesMigration.new(context_base, schema_plural, repo: repo, binary_id: binary_id, users_table: users_table)
56-
content = UserIdentitiesMigration.gen(schema)
53+
defp create_migration_file(%{
54+
repo: repo,
55+
binary_id: binary_id,
56+
users_table: users_table,
57+
schema_plural: schema_plural
58+
}) do
59+
context_base = Pow.app_base(Pow.otp_app())
60+
61+
schema =
62+
UserIdentitiesMigration.new(context_base, schema_plural,
63+
repo: repo,
64+
binary_id: binary_id,
65+
users_table: users_table
66+
)
67+
68+
content = UserIdentitiesMigration.gen(schema)
5769

5870
Migration.create_migration_file(repo, schema.migration_name, content)
5971
end

lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex

+9-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do
4141
|> Map.merge(config)
4242
end
4343

44-
defp create_schema_file(%{binary_id: binary_id, schema_name: schema_name, schema_plural: schema_plural} = config) do
45-
context_app = Map.get(config, :context_app) || Pow.otp_app()
44+
defp create_schema_file(
45+
%{binary_id: binary_id, schema_name: schema_name, schema_plural: schema_plural} = config
46+
) do
47+
context_app = Map.get(config, :context_app) || Pow.otp_app()
4648
context_base = Pow.app_base(context_app)
47-
schema = SchemaModule.new(context_base, schema_name, schema_plural, binary_id: binary_id)
48-
content = SchemaModule.gen(schema)
49-
dir_name = dir_name(schema_name)
50-
file_name = file_name(schema.module)
49+
schema = SchemaModule.new(context_base, schema_name, schema_plural, binary_id: binary_id)
50+
content = SchemaModule.gen(schema)
51+
dir_name = dir_name(schema_name)
52+
file_name = file_name(schema.module)
5153

5254
context_app
5355
|> Pow.context_lib_path(dir_name)
@@ -84,7 +86,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do
8486
|> File.exists?()
8587
|> case do
8688
false -> path
87-
_ -> Mix.raise("schema file can't be created, there is already a schema file in #{path}.")
89+
_ -> Mix.raise("schema file can't be created, there is already a schema file in #{path}.")
8890
end
8991
end
9092
end

lib/mix/tasks/ecto/pow_assent.ecto.install.ex

+17-12
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,28 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do
5151

5252
config
5353
end
54+
5455
defp maybe_run_gen_migration(config, _args), do: config
5556

5657
defp maybe_run_gen_schema(%{schema: true} = config, args) do
5758
SchemaTask.run(args)
5859

5960
config
6061
end
62+
6163
defp maybe_run_gen_schema(config, _args), do: config
6264

6365
defp parse_structure(config) do
64-
context_app = Map.get(config, :context_app) || Pow.otp_app()
66+
context_app = Map.get(config, :context_app) || Pow.otp_app()
6567
context_base = Pow.app_base(context_app)
6668
user_module = Module.concat([context_base, "Users.User"])
6769
user_file = Path.join(["lib", "#{context_app}", "users", "user.ex"])
6870

69-
Map.put(config, :structure, %{context_app: context_app, user_module: user_module, user_file: user_file})
71+
Map.put(config, :structure, %{
72+
context_app: context_app,
73+
user_module: user_module,
74+
user_file: user_file
75+
})
7076
end
7177

7278
defp print_shell_instructions(%{structure: structure} = config) do
@@ -80,7 +86,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do
8086
config
8187

8288
:error ->
83-
Mix.raise "Couldn't install PowAssent! Did you run this inside your Ecto app?"
89+
Mix.raise("Couldn't install PowAssent! Did you run this inside your Ecto app?")
8490
end
8591
end
8692

@@ -96,17 +102,16 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do
96102
needle: "use Pow.Ecto.Schema"
97103
}
98104
],
99-
instructions:
100-
"""
101-
Add the `PowAssent.Ecto.Schema` macro to #{Path.relative_to_cwd(file)} after `use Pow.Ecto.Schema`:
105+
instructions: """
106+
Add the `PowAssent.Ecto.Schema` macro to #{Path.relative_to_cwd(file)} after `use Pow.Ecto.Schema`:
102107
103-
defmodule #{inspect(structure.user_module)} do
104-
use Ecto.Schema
105-
use Pow.Ecto.Schema
106-
use PowAssent.Ecto.Schema
108+
defmodule #{inspect(structure.user_module)} do
109+
use Ecto.Schema
110+
use Pow.Ecto.Schema
111+
use PowAssent.Ecto.Schema
107112
108-
# ...
109-
"""
113+
# ...
114+
"""
110115
}
111116
end
112117
end

lib/mix/tasks/phoenix/pow_assent.phoenix.gen.templates.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.Templates do
2929
end
3030

3131
@templates [
32-
{"registration", ~w(add_user_id)},
32+
{"registration", ~w(add_user_id)}
3333
]
3434

3535
defp create_template_files({config, _parsed, _invalid}) do
36-
structure = Phoenix.parse_structure(config)
37-
web_module = structure[:web_module]
38-
web_prefix = structure[:web_prefix]
36+
structure = Phoenix.parse_structure(config)
37+
web_module = structure[:web_module]
38+
web_prefix = structure[:web_prefix]
3939

4040
Enum.each(@templates, fn {name, actions} ->
4141
Phoenix.create_template_module(Elixir.PowAssent, name, web_module, web_prefix)

lib/mix/tasks/phoenix/pow_assent.phoenix.install.ex

+20-20
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Install do
5555
config
5656

5757
:error ->
58-
Mix.raise "Couldn't install PowAssent! Did you run this inside your Phoenix app?"
58+
Mix.raise("Couldn't install PowAssent! Did you run this inside your Phoenix app?")
5959
end
6060
end
6161

@@ -111,33 +111,32 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Install do
111111
needle: "pow_routes()"
112112
}
113113
],
114-
instructions:
115-
"""
116-
Update `#{Path.relative_to_cwd(file)}` with the PowAssent routes:
114+
instructions: """
115+
Update `#{Path.relative_to_cwd(file)}` with the PowAssent routes:
117116
118-
defmodule #{inspect(structure.web_module)}.Router do
119-
use #{inspect(structure.web_module)}, :router
120-
use Pow.Phoenix.Router
121-
#{router_use_content}
117+
defmodule #{inspect(structure.web_module)}.Router do
118+
use #{inspect(structure.web_module)}, :router
119+
use Pow.Phoenix.Router
120+
#{router_use_content}
122121
123-
# ...
122+
# ...
124123
125-
#{router_pipeline_content}
124+
#{router_pipeline_content}
126125
127-
# ...
126+
# ...
128127
129-
#{router_scope_content}
128+
#{router_scope_content}
130129
131-
scope "/" do
132-
pipe_through :browser
133-
134-
pow_routes()
135-
#{router_routes_macro}
136-
end
130+
scope "/" do
131+
pipe_through :browser
137132
138-
# ...
133+
pow_routes()
134+
#{router_routes_macro}
139135
end
140-
"""
136+
137+
# ...
138+
end
139+
"""
141140
}
142141
end
143142

@@ -146,5 +145,6 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Install do
146145

147146
config
148147
end
148+
149149
defp maybe_run_gen_templates(config, _args), do: config
150150
end

lib/mix/tasks/pow_assent.install.ex

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ defmodule Mix.Tasks.PowAssent.Install do
3737

3838
defp no_umbrella! do
3939
if Project.umbrella?() do
40-
Mix.raise(
41-
"""
42-
mix #{@mix_task} has to be used inside an application directory, but this is an umbrella project.
40+
Mix.raise("""
41+
mix #{@mix_task} has to be used inside an application directory, but this is an umbrella project.
4342
44-
Run mix pow_assent.ecto.install inside your Ecto application directory to create schema module and migrations.
43+
Run mix pow_assent.ecto.install inside your Ecto application directory to create schema module and migrations.
4544
46-
Run mix pow_assent.phoenix.install in your Phoenix application directory for configuration instructions.
47-
""")
45+
Run mix pow_assent.phoenix.install in your Phoenix application directory for configuration instructions.
46+
""")
4847
end
4948

5049
:ok

lib/pow_assent/config.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule PowAssent.Config do
1919
def get(config, key, default \\ nil) do
2020
case Keyword.get(config, key, :not_found) do
2121
:not_found -> get_env_config(config, key, default)
22-
value -> value
22+
value -> value
2323
end
2424
end
2525

@@ -35,7 +35,7 @@ defmodule PowAssent.Config do
3535
config
3636
|> Keyword.get(:otp_app)
3737
|> case do
38-
nil -> Application.get_all_env(env_key)
38+
nil -> Application.get_all_env(env_key)
3939
otp_app -> Application.get_env(otp_app, env_key, [])
4040
end
4141
|> Keyword.get(key, default)
@@ -83,6 +83,7 @@ defmodule PowAssent.Config do
8383
deep_merge(left, right)
8484
end)
8585
end
86+
8687
defp deep_merge(_left, right), do: right
8788

8889
@doc """

0 commit comments

Comments
 (0)