ruby-grape / grape-active_model_serializers

User active_model_serializers with Grape
MIT License
139 stars 68 forks source link

Pass adapter options through calls to render. #63

Closed drn closed 8 years ago

drn commented 8 years ago

This allows for functionality like this:

class UsersApi
  resource :users do
    get '/:id' do
      if conditional
        user
      else
        render user, serializer: ErrorSerializer, adapter: :attributes
      end
    end
  end
end

the only way to pass adapter options was via route_options, which doesn't work if we need to programmatically switch on any of the options (esp because they are cached in between requests as noted here https://github.com/ruby-grape/grape/pull/918)

dblock commented 8 years ago

I like it. It needs a README update please and a rebase.

drn commented 8 years ago

Great! I've updated the README. Let me know if you have any other suggestions

dblock commented 8 years ago

Thinking about this more, help me understand what's going on. Now all options get merged into render. So why do we have ams_meta vs. ams_adapter_options at all?

drn commented 8 years ago

Hey @dblock, sorry for the late reply. The intention there was to not have the meta options pollute the main option pool. Ideally the ams_adapter_options would only be the subset of options explicitly used by AMS adapters, however I took a shortcut here and merged them all in.

I'll check into the internals of AMS and then look for a list of options and whitelist the options that can be passed along in ams_adapter_options. Would that solve your concerns?

drn commented 8 years ago

Okay @dblock - I've pushed up another commit that both explicitly whitelists the adapter options that are passed along as well as adds support for optionally defined extra options. Let me know what you think

dblock commented 8 years ago

This is a lot better. I have some minor-ish concerns above, will merge after those are fixed.

drn commented 8 years ago

Okay! @dblock - I've addressed your comments. Thanks for the review!

dblock commented 8 years ago

Merged.

dblock commented 7 years ago

Hey @drn interested in helping out with this gem? Maybe making a release?