-
-
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.
Allows to set a global ParamBuilder (#1833)
- Loading branch information
Showing
7 changed files
with
104 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Grape | ||
module Config | ||
class Configuration | ||
ATTRIBUTES = %i[ | ||
param_builder | ||
].freeze | ||
|
||
attr_accessor(*ATTRIBUTES) | ||
|
||
def initialize | ||
reset | ||
end | ||
|
||
def reset | ||
self.param_builder = Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder | ||
end | ||
end | ||
|
||
def self.extended(base) | ||
def base.configure | ||
block_given? ? yield(config) : config | ||
end | ||
|
||
def base.config | ||
@configuration ||= Grape::Config::Configuration.new | ||
end | ||
end | ||
end | ||
end | ||
|
||
Grape.extend Grape::Config | ||
Grape.config.reset |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
describe '.configure' do | ||
before do | ||
Grape.configure do |config| | ||
config.param_builder = 42 | ||
end | ||
end | ||
|
||
after do | ||
Grape.config.reset | ||
end | ||
|
||
it 'is configured to the new value' do | ||
expect(Grape.config.param_builder).to eq 42 | ||
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