diff --git a/README.md b/README.md index 6ae5b27..19e72cd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +## Looking for new maintainer(s) + +As much as I love ruby, grape and AMS, I am no longer using them. I think that it makes sense for someone else to pick this project up as a maintainer so that it can be kept more current as I feel I have been neglecting it. If you want to maintain this project, please email me at contact@jrhe.co.uk. I will continue to merge changes in when I have time. Cheers - JRHE + # Grape::ActiveModelSerializers Use [active_model_serializers](https://github.com/rails-api/active_model_serializers) with [Grape](https://github.com/intridea/grape)! @@ -109,6 +113,16 @@ get "/homes" end ``` +### Support for `default_serializer_options` + +```ruby + helper do + def default_serializer_options + {only: params[:only], except: params[:except]} + end + end +``` + ### current_user One of the nice features of ActiveModel::Serializers is that it diff --git a/grape-active_model_serializers.gemspec b/grape-active_model_serializers.gemspec index fc2b060..0ab28a8 100644 --- a/grape-active_model_serializers.gemspec +++ b/grape-active_model_serializers.gemspec @@ -22,5 +22,5 @@ Gem::Specification.new do |gem| gem.add_development_dependency "rspec" gem.add_development_dependency "rack-test" gem.add_development_dependency "rake" - gem.add_development_dependency 'guard-rspec' + gem.add_development_dependency "guard-rspec" end diff --git a/lib/grape-active_model_serializers/formatter.rb b/lib/grape-active_model_serializers/formatter.rb index 87f2b11..1db63bb 100644 --- a/lib/grape-active_model_serializers/formatter.rb +++ b/lib/grape-active_model_serializers/formatter.rb @@ -56,7 +56,7 @@ module Grape end def build_options_from_endpoint(endpoint) - endpoint.namespace_options.merge(endpoint.route_options) + [endpoint.default_serializer_options || {}, endpoint.namespace_options, endpoint.route_options].reduce(:merge) end # array root is the innermost namespace name ('space') if there is one, diff --git a/lib/grape-active_model_serializers/version.rb b/lib/grape-active_model_serializers/version.rb index 0031454..b7b5adb 100644 --- a/lib/grape-active_model_serializers/version.rb +++ b/lib/grape-active_model_serializers/version.rb @@ -1,5 +1,5 @@ module Grape module ActiveModelSerializers - VERSION = '1.2.1' + VERSION = '1.3.1' end end diff --git a/spec/grape-active_model_serializers/endpoint_extension_spec.rb b/spec/grape-active_model_serializers/endpoint_extension_spec.rb index e296dd3..0052e7f 100644 --- a/spec/grape-active_model_serializers/endpoint_extension_spec.rb +++ b/spec/grape-active_model_serializers/endpoint_extension_spec.rb @@ -7,12 +7,12 @@ describe 'Grape::EndpointExtension' do let(:serializer) { Grape::Formatter::ActiveModelSerializers } let(:user) do - Object.new do - def name - 'sven' - end - end - end + Object.new do + def name + 'sven' + end + end + end let(:users) { [user, user] } diff --git a/spec/grape-active_model_serializers/formatter_spec.rb b/spec/grape-active_model_serializers/formatter_spec.rb index 5c29ec9..bed4a93 100644 --- a/spec/grape-active_model_serializers/formatter_spec.rb +++ b/spec/grape-active_model_serializers/formatter_spec.rb @@ -41,6 +41,10 @@ describe Grape::Formatter::ActiveModelSerializers do def endpoint.current_user @current_user ||= User.new(first_name: 'Current user') end + + def endpoint.default_serializer_options + { only: :only, except: :except } + end end subject { described_class.fetch_serializer(user, env) } @@ -50,5 +54,10 @@ describe Grape::Formatter::ActiveModelSerializers do it 'should have correct scope set' do expect(subject.scope.current_user).to eq(endpoint.current_user) end + + it 'should read default serializer options' do + expect(subject.instance_variable_get('@only')).to eq([:only]) + expect(subject.instance_variable_get('@except')).to eq([:except]) + end end end