Skip to content

Commit d10ce5a

Browse files
committed
Ran mix format & fixed syntax warnings, updated dependencies & specified an elixir version.
Also added :ecto to the application list for :dev to resolve a strange compilation issue: - `mix compile` fails complaining it can't find ecto. - `mix test` runs fine. - compiling a downstream project also breaks.
1 parent 38a79c3 commit d10ce5a

22 files changed

Lines changed: 489 additions & 318 deletions

.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elixir 1.17.3
2+
erlang 26.2.5.6

config/config.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is responsible for configuring your application
22
# and its dependencies with the aid of the Mix.Config module.
3-
use Mix.Config
3+
import Config
44

55
# This configuration is loaded before any dependency and is restricted
66
# to this project. If another project depends on this project, this
@@ -28,6 +28,6 @@ use Mix.Config
2828
# here (which is why it is important to import them last).
2929
#
3030

31-
if Mix.env == :test do
31+
if Mix.env() == :test do
3232
import_config "test.exs"
3333
end

config/test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use Mix.Config
1+
import Config
2+
3+
config :as_nested_set, ecto_repos: [AsNestedSet.TestRepo]
24

35
config :as_nested_set, AsNestedSet.TestRepo,
46
hostname: "localhost",

config/test.exs.travis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use Mix.Config
1+
import Config
22

33
config :as_nested_set, AsNestedSet.TestRepo,
44
hostname: "localhost",

lib/as_nested_set.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule AsNestedSet do
22
defmacro __using__(args) do
33
scope = Keyword.get(args, :scope, [])
4+
45
quote do
56
use AsNestedSet.Model
67
use AsNestedSet.Scoped, scope: unquote(scope)
@@ -9,7 +10,7 @@ defmodule AsNestedSet do
910

1011
@type t :: struct
1112

12-
@type executable :: (Ecto.Repo.t -> any)
13+
@type executable :: (Ecto.Repo.t() -> any)
1314

1415
@spec defined?(struct) :: boolean
1516
def defined?(struct) when is_atom(struct) do
@@ -21,12 +22,14 @@ defmodule AsNestedSet do
2122
false
2223
end
2324
end
25+
2426
def defined?(%{__struct__: struct}) do
2527
defined?(struct)
2628
end
29+
2730
def defined?(_), do: false
2831

29-
@spec execute(executable, Ecto.Repo.t) :: any
32+
@spec execute(executable, Ecto.Repo.t()) :: any
3033
def execute(call, repo) do
3134
call.(repo)
3235
end

lib/as_nested_set/helper.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule AsNestedSet.Helper do
2-
32
def get_column_name(%{__struct__: struct}, field) do
43
get_column_name(struct, field)
54
end
@@ -19,6 +18,4 @@ defmodule AsNestedSet.Helper do
1918
def fields(module) when is_atom(module) do
2019
module.__as_nested_set_fields__()
2120
end
22-
23-
24-
end
21+
end

lib/as_nested_set/model.ex

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule AsNestedSet.Model do
2-
32
defmacro __using__(_) do
43
quote do
54
@node_id_column :id
@@ -18,36 +17,43 @@ defmodule AsNestedSet.Model do
1817
end
1918

2019
defp define_accessors(names, env) do
21-
fields = Enum.map(names, fn
22-
name ->
23-
attribute_name = String.to_atom("#{name}_column")
24-
column_name = Module.get_attribute(env.module, attribute_name)
25-
{name, column_name}
26-
end) |> Enum.into(%{})
20+
fields =
21+
Enum.map(names, fn
22+
name ->
23+
attribute_name = String.to_atom("#{name}_column")
24+
column_name = Module.get_attribute(env.module, attribute_name)
25+
{name, column_name}
26+
end)
27+
|> Enum.into(%{})
2728

2829
Enum.map(fields, fn
29-
{name, column_name}->
30+
{name, column_name} ->
3031
quote do
3132
def __as_nested_set_column_name__(unquote(name)) do
3233
unquote(column_name)
3334
end
35+
3436
def __as_nested_set_get_field__(model, unquote(name)) do
3537
Map.get(model, unquote(column_name))
3638
end
39+
3740
def __as_nested_set_set_field__(model, unquote(name), value) do
3841
Map.put(model, unquote(column_name), value)
3942
end
4043
end
41-
end) ++ [
42-
quote do
43-
def __as_nested_set_field__(field) do
44-
raise ArgumentError, "Unknown AsNestedSet field #{inspect field} for #{inspect __MODULE__}"
44+
end) ++
45+
[
46+
quote do
47+
def __as_nested_set_field__(field) do
48+
raise ArgumentError,
49+
"Unknown AsNestedSet field #{inspect(field)} for #{inspect(__MODULE__)}"
50+
end
51+
52+
def __as_nested_set_get_field__(model, _), do: nil
53+
def __as_nested_set_set_field__(model, _, _), do: model
54+
def __as_nested_set_fields__(), do: unquote(fields |> Macro.escape())
4555
end
46-
def __as_nested_set_get_field__(model, _), do: nil
47-
def __as_nested_set_set_field__(model, _, _), do: model
48-
def __as_nested_set_fields__(), do: unquote(fields |> Macro.escape)
49-
end
50-
]
56+
]
5157
end
5258

5359
defp define_queriers(_env) do

0 commit comments

Comments
 (0)