Skip to content

Commit

Permalink
[Fix] resource name inference for "Serializer"
Browse files Browse the repository at this point in the history
The previous implementation only supports the class whose name
ends with "Resource".
Alba supports "Serializer" class as well.
This implementation is kind of naive but it works anyway.
  • Loading branch information
okuramasafumi committed Aug 1, 2023
1 parent b10a369 commit 1695af4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/alba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def infer_resource_class(name, nesting: nil)
raise Alba::Error, 'Inference is disabled so Alba cannot infer resource name. Set inflector before use.' unless Alba.inflector

const_parent = nesting.nil? ? Object : Object.const_get(nesting)
const_parent.const_get("#{inflector.classify(name)}Resource")
begin
const_parent.const_get("#{inflector.classify(name)}Resource")
rescue # Retry for serializer
const_parent.const_get("#{inflector.classify(name)}Serializer")
end
end

# Configure Alba to symbolize keys
Expand Down

0 comments on commit 1695af4

Please sign in to comment.