Skip to content

Commit

Permalink
Allow the suffix to be manually set (#30)
Browse files Browse the repository at this point in the history
Sometimes the automatically generated suffix might not match what we
want.

For example `SomeSchema.Nested` by default generates as `all_nested`
rather than `all_some_schema_nested`. This update will let us pass
`suffix: "some_schema_nested"` to manually set this.

Open to feedback on how to approach this, but the PR was simple enough
to go ahead and do as a suggestion (and solves for my use case)
  • Loading branch information
jakeprem authored Nov 18, 2024
1 parent eb074d3 commit 8a9f447
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/option_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ defmodule EctoResource.OptionParser do

@spec create_suffix(module, list()) :: String.t()
def create_suffix(schema, options) when is_list(options) do
if Keyword.get(options, :suffix) == false do
""
else
Helpers.underscore_module_name(schema)
case Keyword.get(options, :suffix) do
false -> ""
manual when is_binary(manual) -> manual
_ -> Helpers.underscore_module_name(schema)
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/ecto_resource/option_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,9 @@ defmodule EctoResource.OptionParserTest do
assert OptionParser.create_suffix(TestSchema, suffix: false, except: [:create!, :create]) ==
""
end

test "when suffix is set to a string, it returns that string directly" do
assert OptionParser.create_suffix(TestSchema, suffix: "some_thing") == "some_thing"
end
end
end

0 comments on commit 8a9f447

Please sign in to comment.