From f624ed09abba4a0bae64eb699c9fc2e3f9bdc2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 24 Sep 2020 22:41:04 +0000 Subject: [PATCH] Don't make rexml an dependency of activesupport rexml is only used in the xml_mini backend and it should be the users choice if they want to use that feature or not. If they do we will warn them that installing rexml is needed like we do with all backends. --- Gemfile | 1 + Gemfile.lock | 2 +- activesupport/activesupport.gemspec | 1 - activesupport/lib/active_support/xml_mini/rexml.rb | 10 +++++++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index e5c0ebcbed9..a58e183a009 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,7 @@ gem "dalli" gem "listen", "~> 3.2", require: false, github: "guard/listen" gem "libxml-ruby", platforms: :ruby gem "connection_pool", require: false +gem "rexml", require: false # for railties app_generator_test gem "bootsnap", ">= 1.4.4", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 336c64155bd..69630d0e2e7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,6 @@ PATH concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) - rexml tzinfo (~> 2.0) zeitwerk (~> 2.3) rails (6.1.0.alpha) @@ -607,6 +606,7 @@ DEPENDENCIES redis-namespace! resque resque-scheduler + rexml rouge rubocop (>= 0.90) rubocop-packaging diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index 9cffc2696c9..72cd995f02b 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -38,5 +38,4 @@ Gem::Specification.new do |s| s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2" s.add_dependency "zeitwerk", "~> 2.3" s.add_dependency "minitest", ">= 5.1" - s.add_dependency "rexml" end diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb index 8d6e3af0662..626e0122ac7 100644 --- a/activesupport/lib/active_support/xml_mini/rexml.rb +++ b/activesupport/lib/active_support/xml_mini/rexml.rb @@ -25,7 +25,7 @@ module ActiveSupport if data.eof? {} else - silence_warnings { require "rexml/document" } unless defined?(REXML::Document) + require_rexml unless defined?(REXML::Document) doc = REXML::Document.new(data) if doc.root @@ -38,6 +38,14 @@ module ActiveSupport end private + + def require_rexml + silence_warnings { require "rexml/document" } + rescue LoadError => e + $stderr.puts "You don't have rexml installed in your application. Please add it to your Gemfile and run bundle install" + raise e + end + # Convert an XML element and merge into the hash # # hash::