-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix adapter inflection bug for api -> API #1006
Conversation
cc @kurko @joaomdmoura your thoughts? |
adapter_map.update(name.to_s.underscore => klass) | ||
end | ||
|
||
def get(adapter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean on the serializer? I can dedupe that in a new commit or pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, it's exactly the same logic. IMHO it's related to this PR, check this out:
We can replace the actual code:
def self.adapter
adapter_class = case config.adapter
when Symbol
ActiveModel::Serializer::Adapter.adapter_class(config.adapter)
when Class
config.adapter
end
unless adapter_class
valid_adapters = Adapter.constants.map { |klass| ":#{klass.to_s.downcase}" }
raise ArgumentError, "Unknown adapter: #{config.adapter}. Valid adapters are: #{valid_adapters}"
end
adapter_class
end
By something like:
def self.adapter
ActiveModel::Serializer::Adapter.adapter_class(config.adapter)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look when I'm next at a computer. Do you like the new interface and behavior? Or have an alternative in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! Yup, really liked it! If we can make it the only place to deal with this logic then I'm okay with it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I was a little uncertain about the naming
So, the two methods havr slightly different behavior
The one in the adapter would return nil if none found, but the one in the serializer raises an argument error
So, i was thinking of having get and get! on the adapter
Needs some thought where nil is desired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another commit to consider. I've been playing with the interface for success/failurre handling of finding the adapter by name and whether to find it by constants, or safe constantize, etc. So, this is for consideration as a way to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bf4 it's seems to me nil
is never desired. What are your thoughts about keep the argument error approach and remote get!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'd still like to allow for user defined failure handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll notice that get
can take a block to handle adapter not found, and is used by get!
def get!(adapter)
get(adapter) do |failure_message| fail ArgumentError, failure_message end
end
7f83aa1
to
9b33cf9
Compare
It was easier to handle the simple case of api being inflected to API rather than Api via sub (not sure that's the most performant way. I didn't investigate), rather than have a whole bunch of changes around that either mutating |
The stuff with the registered adapter I'll do in another PR, because it also brings up issues with autoloading |
No, this PR is still required. I just think the complexity I was introducing wasn't required for the range of inflection failures |
Okay @bf4. Good, it seems the most straightforward solution for me as well. I'm merging it. |
Fix adapter inflection bug for api -> API
Bug: #993
Summary
Some work done in here was moved in #1017