From ca3604516b5725b30a290482c219ca55fca5de49 Mon Sep 17 00:00:00 2001 From: Bobby McDonald Date: Wed, 2 Oct 2019 10:48:19 -0400 Subject: Make Hashie play nice with Rails 6 Hash#except method (#479) --- lib/hashie/extensions/active_support/core_ext/hash.rb | 14 ++++++++++++++ lib/hashie/railtie.rb | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 lib/hashie/extensions/active_support/core_ext/hash.rb (limited to 'lib') diff --git a/lib/hashie/extensions/active_support/core_ext/hash.rb b/lib/hashie/extensions/active_support/core_ext/hash.rb new file mode 100644 index 0000000..b8d71f7 --- /dev/null +++ b/lib/hashie/extensions/active_support/core_ext/hash.rb @@ -0,0 +1,14 @@ +module Hashie + module Extensions + module ActiveSupport + module CoreExt + module Hash + def except(*keys) + string_keys = keys.map { |key| convert_key(key) } + super(*string_keys) + end + end + end + end + end +end diff --git a/lib/hashie/railtie.rb b/lib/hashie/railtie.rb index 65cd007..c5f05b7 100644 --- a/lib/hashie/railtie.rb +++ b/lib/hashie/railtie.rb @@ -7,6 +7,13 @@ begin initializer 'hashie.configure_logger', after: 'initialize_logger' do Hashie.logger = Rails.logger end + + initializer 'hashie.patch_hash_except', after: 'load_active_support' do + if Rails::VERSION::MAJOR >= 6 + require 'hashie/extensions/active_support/core_ext/hash' + Hashie::Mash.send(:include, Hashie::Extensions::ActiveSupport::CoreExt::Hash) + end + end end end rescue LoadError => e -- cgit v1.2.1