-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extended ParamBulder to be included in an entire API or namespace.
- Loading branch information
Showing
14 changed files
with
272 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
lib/grape/extensions/active_support/hash_with_indifferent_access.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Grape | ||
module Extensions | ||
module ActiveSupport | ||
module HashWithIndifferentAccess | ||
extend ::ActiveSupport::Concern | ||
|
||
included do | ||
namespace_inheritable(:build_params_with, Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder) | ||
end | ||
|
||
def params_builder | ||
Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder | ||
end | ||
|
||
module ParamBuilder | ||
def build_params | ||
params = ::ActiveSupport::HashWithIndifferentAccess[rack_params] | ||
params.deep_merge!(grape_routing_args) if env[Grape::Env::GRAPE_ROUTING_ARGS] | ||
params | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
spec/grape/extensions/param_builders/has_with_indifferent_access_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'spec_helper' | ||
|
||
describe Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder do | ||
subject { Class.new(Grape::API) } | ||
|
||
def app | ||
subject | ||
end | ||
|
||
describe 'in an endpoint' do | ||
context '#params' do | ||
before do | ||
subject.params do | ||
build_with Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder | ||
end | ||
|
||
subject.get do | ||
params.class | ||
end | ||
end | ||
|
||
it 'should be of type Hash' do | ||
get '/' | ||
expect(last_response.status).to eq(200) | ||
expect(last_response.body).to eq('ActiveSupport::HashWithIndifferentAccess') | ||
end | ||
end | ||
end | ||
|
||
describe 'in an api' do | ||
before do | ||
subject.send(:include, Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder) | ||
end | ||
|
||
context '#params' do | ||
before do | ||
subject.get do | ||
params.class | ||
end | ||
end | ||
|
||
it 'should be Hash' do | ||
get '/' | ||
expect(last_response.status).to eq(200) | ||
expect(last_response.body).to eq('ActiveSupport::HashWithIndifferentAccess') | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.