Skip to content

Commit

Permalink
Merge pull request ruby-grape#1125 from marshall-lee/use_extract_options
Browse files Browse the repository at this point in the history
Use extract_options!
  • Loading branch information
dblock committed Aug 26, 2015
2 parents 8c2f83c + 41d6fac commit cc1e46f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Parameters
# end
def use(*names)
named_params = Grape::DSL::Configuration.stacked_hash_to_hash(@api.namespace_stackable(:named_params)) || {}
options = names.last.is_a?(Hash) ? names.pop : {}
options = names.extract_options!
names.each do |name|
params_block = named_params.fetch(name) do
fail "Params :#{name} not found!"
Expand Down Expand Up @@ -86,7 +86,7 @@ def use(*names)
def requires(*attrs, &block)
orig_attrs = attrs.clone

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

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

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

# check type for optional parameter group
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/request_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def rescue_from(*args, &block)
handler = block
end

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

if args.include?(:all)
Expand Down
3 changes: 1 addition & 2 deletions lib/grape/dsl/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ module ClassMethods
#
def version(*args, &block)
if args.any?
options = args.pop if args.last.is_a? Hash
options ||= {}
options = args.extract_options!
options = { using: :path }.merge(options)

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

0 comments on commit cc1e46f

Please sign in to comment.