Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [#2725](https://github.com/ruby-grape/grape/pull/2725): Encapsulate `Grape::Validations::Validators::Base` state behind readers; add `required?`/`allow_blank?` predicates - [@ericproulx](https://github.com/ericproulx).
* [#2726](https://github.com/ruby-grape/grape/pull/2726): Reuse one `AttributesIterator` per validator and drop the unused `Enumerable` mixin - [@ericproulx](https://github.com/ericproulx).
* [#2728](https://github.com/ruby-grape/grape/pull/2728): Deprecate passing a positional options Hash to `auth`/`http_basic`/`http_digest`; pass keyword arguments instead - [@ericproulx](https://github.com/ericproulx).
* [#2733](https://github.com/ruby-grape/grape/pull/2733): Drop the dead `active_support/core_ext/hash/reverse_merge` require; call `ActiveSupport::HashWithIndifferentAccess.new(...)` directly at call sites - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'active_support/core_ext/hash/deep_merge'
require 'active_support/core_ext/hash/deep_transform_values'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/hash_with_indifferent_access'
require 'active_support/core_ext/module/delegation' # delegate_missing_to
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/deep_dup'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def delete(name, **opts)
def cookies
return @cookies unless @cookies.is_a?(Proc)

@cookies = @cookies.call.with_indifferent_access
@cookies = ActiveSupport::HashWithIndifferentAccess.new(@cookies.call)
end

def send_cookies
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/auth/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def auth(type = nil, *legacy_options, **options, &block)
return namespace_inheritable[:auth] unless type

options = merge_legacy_auth_options(:auth, legacy_options, options)
namespace_inheritable[:auth] = options.reverse_merge(type: type.to_sym, proc: block)
namespace_inheritable[:auth] = { type: type.to_sym, proc: block }.merge!(options)
use Grape::Middleware::Auth::Base, namespace_inheritable[:auth]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def framework_default(endpoint)

def error!(message, status = default_status, headers = {}, backtrace = [], original_exception = nil)
env[Grape::Env::API_ENDPOINT].status(status) # not error! inside route
merged_headers = headers.reverse_merge(Rack::CONTENT_TYPE => content_type)
merged_headers = { Rack::CONTENT_TYPE => content_type }.merge!(headers)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering how much faster merge! is vs. merge here.

● Benchmark merge vs merge! on a fresh hash literal (shell)
  │ ruby -r benchmark -e '
  │ require "benchmark/ips" rescue nil
  │ 
  │ headers = { "X-Custom" => "value", "X-Other" => "thing" }
  │ content_type = "application/json"…
  └ 19 lines...

● Yes, merge! is ~19% faster in this pattern.

error = Grape::Exceptions::ErrorResponse.new(
status:, message:, headers: merged_headers, backtrace:, original_exception:
)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/precomputed_content_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def content_type
private

def content_types_indifferent_access
@content_types_indifferent_access ||= content_types.with_indifferent_access
@content_types_indifferent_access ||= ActiveSupport::HashWithIndifferentAccess.new(content_types)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/params_builder/hash_with_indifferent_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Grape
module ParamsBuilder
class HashWithIndifferentAccess < Base
def self.call(params)
params.with_indifferent_access
ActiveSupport::HashWithIndifferentAccess.new(params)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/util/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def build_short_name(klass)
end

def registry
@registry ||= {}.with_indifferent_access
@registry ||= ActiveSupport::HashWithIndifferentAccess.new
end
end
end
Expand Down
Loading