Skip to content

Commit 8a9f447

Browse files
authored
Allow the suffix to be manually set (#30)
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)
1 parent eb074d3 commit 8a9f447

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/option_parser.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ defmodule EctoResource.OptionParser do
6363

6464
@spec create_suffix(module, list()) :: String.t()
6565
def create_suffix(schema, options) when is_list(options) do
66-
if Keyword.get(options, :suffix) == false do
67-
""
68-
else
69-
Helpers.underscore_module_name(schema)
66+
case Keyword.get(options, :suffix) do
67+
false -> ""
68+
manual when is_binary(manual) -> manual
69+
_ -> Helpers.underscore_module_name(schema)
7070
end
7171
end
7272

test/ecto_resource/option_parser_test.exs

+4
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,9 @@ defmodule EctoResource.OptionParserTest do
292292
assert OptionParser.create_suffix(TestSchema, suffix: false, except: [:create!, :create]) ==
293293
""
294294
end
295+
296+
test "when suffix is set to a string, it returns that string directly" do
297+
assert OptionParser.create_suffix(TestSchema, suffix: "some_thing") == "some_thing"
298+
end
295299
end
296300
end

0 commit comments

Comments
 (0)