Skip to content

Commit

Permalink
improvement: use new :csv option type from igniter
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 14, 2024
1 parent cb3137c commit e3c735f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 31 deletions.
15 changes: 0 additions & 15 deletions lib/ash/igniter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,4 @@ defmodule Ash.Igniter do
Igniter.add_task(igniter, "ash.codegen", [name])
end
end

def csv_option(options, key, modifier \\ & &1) do
values = Keyword.get_values(options, key)

values =
values
|> List.wrap()
|> Enum.join(",")
|> String.split(",", trim: true)
|> then(modifier)

options
|> Keyword.delete(key)
|> Keyword.put(key, values)
end
end
19 changes: 9 additions & 10 deletions lib/mix/tasks/gen/ash.gen.resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ defmodule Mix.Tasks.Ash.Gen.Resource do
positional: [:resource],
example: @example,
schema: [
attribute: :keep,
relationship: :keep,
default_actions: :keep,
attribute: :csv,
relationship: :csv,
default_actions: :csv,
uuid_primary_key: :string,
uuid_v7_primary_key: :string,
integer_primary_key: :string,
domain: :string,
extend: :keep,
extend: :csv,
base: :string,
timestamps: :boolean
],
Expand Down Expand Up @@ -90,12 +90,11 @@ defmodule Mix.Tasks.Ash.Gen.Resource do

options =
options
|> Ash.Igniter.csv_option(:default_actions, fn values ->
Enum.sort_by(values, &(&1 in ["create", "update"]))
end)
|> Ash.Igniter.csv_option(:attribute)
|> Ash.Igniter.csv_option(:relationship)
|> Ash.Igniter.csv_option(:extend)
|> Keyword.update(
:default_actions,
[],
fn defaults -> Enum.sort_by(defaults, &(&1 in ["create", "update"])) end
)
|> Keyword.put_new(:base, "Ash.Resource")

base =
Expand Down
6 changes: 2 additions & 4 deletions lib/mix/tasks/patch/ash.patch.extend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ defmodule Mix.Tasks.Ash.Patch.Extend do

opts =
[
subjects: subject,
extensions: extensions
subjects: String.split(subject, ",", trim: true),
extensions: String.split(Enum.join(extensions, ","), ",", trim: true)
]
|> Ash.Igniter.csv_option(:extensions)
|> Ash.Igniter.csv_option(:subjects)

extensions = opts[:extensions]

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ defmodule Ash.MixProject do
{:simple_sat, "~> 0.1 and >= 0.1.1", optional: true},

# Code Generators
{:igniter, "~> 0.3 and >= 0.3.36"},
{:igniter, "~> 0.3 and >= 0.3.61"},

# IO Utilities
{:owl, "~> 0.11"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"git_ops": {:hex, :git_ops, "2.6.2", "1e03e44d1b41e91cf39b47d214d515a0d67d44a7fda13ef131bb70bd706dd398", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fc0200fbc6d2784e2f3b9be200ce63e523d0d9ff527c6308490c3d6d325d5e6f"},
"glob_ex": {:hex, :glob_ex, "0.1.9", "b97a25392f5339e49f587e5b24c468c6a4f38299febd5ec85c5f8bb2e42b5c1e", [:mix], [], "hexpm", "be72e584ad1d8776a4d134d4b6da1bac8b80b515cdadf0120e0920b9978d7f01"},
"ham": {:hex, :ham, "0.3.0", "7cd031b4a55fba219c11553e7b13ba73bd86eab4034518445eff1e038cb9a44d", [:mix], [], "hexpm", "7d6c6b73d7a6a83233876cc1b06a4d9b5de05562b228effda4532f9a49852bf6"},
"igniter": {:hex, :igniter, "0.3.57", "ecbbe7b0eeb62e28b33c84af3ab554da11fb1bba1cf9ad5473ed776b26fb30a6", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "086a9430bc55b7ace4eb67a1c71649a25f9cf64c634df405aae2987b485b3fb4"},
"igniter": {:hex, :igniter, "0.3.61", "4c6a3c52d5b9773adc09d9185f2994d56572723d17144af9b046c7b558fdfd1b", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "06946f046ec4b381bede336c878249125b890dce6ca43c7ca03784a02f9c160a"},
"iterex": {:hex, :iterex, "0.1.2", "58f9b9b9a22a55cbfc7b5234a9c9c63eaac26d276b3db80936c0e1c60355a5a6", [:mix], [], "hexpm", "2e103b8bcc81757a9af121f6dc0df312c9a17220f302b1193ef720460d03029d"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"},
Expand Down

0 comments on commit e3c735f

Please sign in to comment.