aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-15 15:50:39 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-15 15:50:39 -0200
commitcf3eb6dab0e89ea6b64b9bdb24d4df3e8006da7b (patch)
treefd397b746d6ff3cf64931c1671b34d16c43d1088 /activesupport/lib
parenta8c3ea90f1490da4404aa1cea6fc6209f6b9b99b (diff)
parent1fab2002e3385c40ef48008b649d78ce5e16a868 (diff)
downloadrails-cf3eb6dab0e89ea6b64b9bdb24d4df3e8006da7b.tar.gz
rails-cf3eb6dab0e89ea6b64b9bdb24d4df3e8006da7b.tar.bz2
rails-cf3eb6dab0e89ea6b64b9bdb24d4df3e8006da7b.zip
Merge pull request #8219 from nikitug/threadsafe_xmlmini_with_backend
Make XmlMini.with_backend usable with threads Conflicts: activesupport/CHANGELOG.md
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/xml_mini.rb38
1 files changed, 29 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index 88f9acb588..d082a0a499 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -76,23 +76,24 @@ module ActiveSupport
)
end
- attr_reader :backend
delegate :parse, :to => :backend
+ def backend
+ current_thread_backend || @backend
+ end
+
def backend=(name)
- if name.is_a?(Module)
- @backend = name
- else
- require "active_support/xml_mini/#{name.downcase}"
- @backend = ActiveSupport.const_get("XmlMini_#{name}")
- end
+ backend = name && cast_backend_name_to_module(name)
+ self.current_thread_backend = backend if current_thread_backend
+ @backend = backend
end
def with_backend(name)
- old_backend, self.backend = backend, name
+ old_backend = current_thread_backend
+ self.current_thread_backend = name && cast_backend_name_to_module(name)
yield
ensure
- self.backend = old_backend
+ self.current_thread_backend = old_backend
end
def to_tag(key, value, options)
@@ -163,6 +164,25 @@ module ActiveSupport
f.content_type = entity['content_type']
f
end
+
+ private
+
+ def current_thread_backend
+ Thread.current[:xml_mini_backend]
+ end
+
+ def current_thread_backend=(name)
+ Thread.current[:xml_mini_backend] = name && cast_backend_name_to_module(name)
+ end
+
+ def cast_backend_name_to_module(name)
+ if name.is_a?(Module)
+ name
+ else
+ require "active_support/xml_mini/#{name.downcase}"
+ ActiveSupport.const_get("XmlMini_#{name}")
+ end
+ end
end
XmlMini.backend = 'REXML'