Skip to content

Commit 694824f

Browse files
committed
Use reverse_merge.
1 parent 079b2aa commit 694824f

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

lib/grape.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require 'active_support/core_ext/object/blank'
1313
require 'active_support/core_ext/array/extract_options'
1414
require 'active_support/core_ext/hash/deep_merge'
15+
require 'active_support/core_ext/hash/reverse_merge'
1516
require 'active_support/core_ext/hash/except'
1617
require 'active_support/dependencies/autoload'
1718
require 'active_support/notifications'

lib/grape/dsl/inside_route.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def error!(message, status = nil, headers = nil)
7070
# @param options [Hash] The options used when redirect.
7171
# :permanent, default false.
7272
def redirect(url, options = {})
73-
merged_options = { permanent: false }.merge(options)
73+
merged_options = options.reverse_merge(permanent: false)
7474
if merged_options[:permanent]
7575
status 301
7676
else

lib/grape/dsl/routing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module ClassMethods
2929
def version(*args, &block)
3030
if args.any?
3131
options = args.extract_options!
32-
options = { using: :path }.merge(options)
32+
options = options.reverse_merge(using: :path)
3333

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

lib/grape/exceptions/base.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ def resolution(key, attributes)
5151

5252
def translate_attributes(keys, options = {})
5353
keys.map do |key|
54-
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", { default: key }.merge(options))
54+
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", options.reverse_merge(default: key))
5555
end.join(', ')
5656
end
5757

5858
def translate_attribute(key, options = {})
59-
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", { default: key }.merge(options))
59+
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", options.reverse_merge(default: key))
6060
end
6161

6262
def translate_message(key, options = {})
63-
translate("#{BASE_MESSAGES_KEY}.#{key}", { default: '' }.merge(options))
63+
translate("#{BASE_MESSAGES_KEY}.#{key}", options.reverse_merge(default: ''))
6464
end
6565

6666
def translate(key, options = {})

lib/grape/middleware/auth/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module ClassMethods
1212
# only `:http_basic`, `:http_digest` are supported.
1313
def auth(type = nil, options = {}, &block)
1414
if type
15-
namespace_inheritable(:auth, { type: type.to_sym, proc: block }.merge(options))
15+
namespace_inheritable(:auth, options.reverse_merge(type: type.to_sym, proc: block))
1616
use Grape::Middleware::Auth::Base, namespace_inheritable(:auth)
1717
else
1818
namespace_inheritable(:auth)

lib/grape/middleware/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def exec_handler(e, &handler)
5959
end
6060

6161
def error!(message, status = options[:default_status], headers = {}, backtrace = [])
62-
headers = { Grape::Http::Headers::CONTENT_TYPE => content_type }.merge(headers)
62+
headers = headers.reverse_merge(Grape::Http::Headers::CONTENT_TYPE => content_type)
6363
rack_response(format_message(message, backtrace), status, headers)
6464
end
6565

0 commit comments

Comments
 (0)