petty annoyance of alias_method_chain

So it appears you can’t alias_method_chain []=. Rightly so you’d end up trying to do something like

def []=_with_rescue
  []=_without_rescue
end
alias_method_chain :[]=, :rescue

The resulting method names are of course invalid. So you have to do it longhand

require 'action_dispatch/middleware/cookies'
# action_dispatch/middleware/cookies.rb
module ActionDispatch
  class Cookies
    class SignedCookieJar
      def assign_with_overflow_rescue(name, options)
        assign_without_overflow_rescue(name, options)
      rescue ActionDispatch::Cookies::CookieOverflow => e
        SiteMailer.delay.error(e, key: key, original_options: original_options, encoded_size: options[:value].size)
      end
      alias_method :assign_without_overflow_rescue, :[]=
      alias_method :[]=, :assign_with_overflow_rescue
    end
  end
end