Skip to content

Commit

Permalink
Allow the suffix to be manually set
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
create_nested rather than create_some_schema_nested. Also supports
other cases where the schema doesn't match the context names, although
using it that way is probably unwise.
  • Loading branch information
jakeprem authored and joseph-lozano committed Nov 18, 2024
1 parent eb074d3 commit a22ee89
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 a22ee89

Please sign in to comment.