Skip to content

Commit cc1e46f

Browse files
committed
Merge pull request #1125 from marshall-lee/use_extract_options
Use extract_options!
2 parents 8c2f83c + 41d6fac commit cc1e46f

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

lib/grape/dsl/parameters.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Parameters
3131
# end
3232
def use(*names)
3333
named_params = Grape::DSL::Configuration.stacked_hash_to_hash(@api.namespace_stackable(:named_params)) || {}
34-
options = names.last.is_a?(Hash) ? names.pop : {}
34+
options = names.extract_options!
3535
names.each do |name|
3636
params_block = named_params.fetch(name) do
3737
fail "Params :#{name} not found!"
@@ -86,7 +86,7 @@ def use(*names)
8686
def requires(*attrs, &block)
8787
orig_attrs = attrs.clone
8888

89-
opts = attrs.last.is_a?(Hash) ? attrs.pop.clone : {}
89+
opts = attrs.extract_options!.clone
9090
opts[:presence] = true
9191

9292
if opts[:using]
@@ -105,7 +105,7 @@ def requires(*attrs, &block)
105105
def optional(*attrs, &block)
106106
orig_attrs = attrs.clone
107107

108-
opts = attrs.last.is_a?(Hash) ? attrs.pop.clone : {}
108+
opts = attrs.extract_options!.clone
109109
type = opts[:type]
110110

111111
# check type for optional parameter group

lib/grape/dsl/request_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def rescue_from(*args, &block)
104104
handler = block
105105
end
106106

107-
options = args.last.is_a?(Hash) ? args.pop : {}
107+
options = args.extract_options!
108108
handler ||= proc { options[:with] } if options.key?(:with)
109109

110110
if args.include?(:all)

lib/grape/dsl/routing.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ module ClassMethods
2828
#
2929
def version(*args, &block)
3030
if args.any?
31-
options = args.pop if args.last.is_a? Hash
32-
options ||= {}
31+
options = args.extract_options!
3332
options = { using: :path }.merge(options)
3433

3534
fail Grape::Exceptions::MissingVendorOption.new if options[:using] == :header && !options.key?(:vendor)

0 commit comments

Comments
 (0)