aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-02-01 17:54:45 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-02-01 17:54:45 +0000
commita390b2629a7de7cb8a8a5370aa493283c4a3f066 (patch)
tree95450d80d313e13c6a235c722761ea70aca54555 /activesupport
parenta4ff4fd2c38175b38af928da2b5cae2b6bb19da7 (diff)
parent3be0ad60e4fcdafd4817508a21340dbf1bda6cb4 (diff)
downloadrails-a390b2629a7de7cb8a8a5370aa493283c4a3f066.tar.gz
rails-a390b2629a7de7cb8a8a5370aa493283c4a3f066.tar.bz2
rails-a390b2629a7de7cb8a8a5370aa493283c4a3f066.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/dependencies.rb19
-rw-r--r--activesupport/lib/active_support/xml_mini.rb182
2 files changed, 106 insertions, 95 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 7ce9adec2c..2badad5f5f 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -51,6 +51,9 @@ module ActiveSupport #:nodoc:
mattr_accessor :constant_watch_stack
self.constant_watch_stack = []
+ mattr_accessor :constant_watch_stack_mutex
+ self.constant_watch_stack_mutex = Mutex.new
+
# Module includes this module
module ModuleConstMissing #:nodoc:
def self.included(base) #:nodoc:
@@ -509,7 +512,9 @@ module ActiveSupport #:nodoc:
[mod_name, initial_constants]
end
- constant_watch_stack.concat watch_frames
+ constant_watch_stack_mutex.synchronize do
+ constant_watch_stack.concat watch_frames
+ end
aborting = true
begin
@@ -526,8 +531,10 @@ module ActiveSupport #:nodoc:
new_constants = mod.local_constant_names - prior_constants
# Make sure no other frames takes credit for these constants.
- constant_watch_stack.each do |frame_name, constants|
- constants.concat new_constants if frame_name == mod_name
+ constant_watch_stack_mutex.synchronize do
+ constant_watch_stack.each do |frame_name, constants|
+ constants.concat new_constants if frame_name == mod_name
+ end
end
new_constants.collect do |suffix|
@@ -549,8 +556,10 @@ module ActiveSupport #:nodoc:
# Remove the stack frames that we added.
if defined?(watch_frames) && ! watch_frames.blank?
frame_ids = watch_frames.collect { |frame| frame.object_id }
- constant_watch_stack.delete_if do |watch_frame|
- frame_ids.include? watch_frame.object_id
+ constant_watch_stack_mutex.synchronize do
+ constant_watch_stack.delete_if do |watch_frame|
+ frame_ids.include? watch_frame.object_id
+ end
end
end
end
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index bfc3d7b00b..ce3f50620d 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -4,108 +4,110 @@
# Copyright:: Copyright (c) 2008 Joseph Holsten
# Copyright:: Copyright (c) 2003-2006 Maik Schmidt <contact@maik-schmidt.de>
# License:: Distributes under the same terms as Ruby.
-module XmlMini
- extend self
+module ActiveSupport
+ module XmlMini
+ extend self
- CONTENT_KEY = '__content__'.freeze
+ CONTENT_KEY = '__content__'.freeze
- # Parse an XML Document string into a simple hash
- #
- # Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
- # and uses the defaults from ActiveSupport
- #
- # string::
- # XML Document string to parse
- def parse(string)
- require 'rexml/document' unless defined?(REXML::Document)
- doc = REXML::Document.new(string)
- merge_element!({}, doc.root)
- end
-
- private
- # Convert an XML element and merge into the hash
+ # Parse an XML Document string into a simple hash
#
- # hash::
- # Hash to merge the converted element into.
- # element::
- # XML element to merge into hash
- def merge_element!(hash, element)
- merge!(hash, element.name, collapse(element))
+ # Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
+ # and uses the defaults from ActiveSupport
+ #
+ # string::
+ # XML Document string to parse
+ def parse(string)
+ require 'rexml/document' unless defined?(REXML::Document)
+ doc = REXML::Document.new(string)
+ merge_element!({}, doc.root)
end
- # Actually converts an XML document element into a data structure.
- #
- # element::
- # The document element to be collapsed.
- def collapse(element)
- hash = get_attributes(element)
+ private
+ # Convert an XML element and merge into the hash
+ #
+ # hash::
+ # Hash to merge the converted element into.
+ # element::
+ # XML element to merge into hash
+ def merge_element!(hash, element)
+ merge!(hash, element.name, collapse(element))
+ end
- if element.has_elements?
- element.each_element {|child| merge_element!(hash, child) }
- merge_texts!(hash, element) unless empty_content?(element)
- hash
- else
- merge_texts!(hash, element)
+ # Actually converts an XML document element into a data structure.
+ #
+ # element::
+ # The document element to be collapsed.
+ def collapse(element)
+ hash = get_attributes(element)
+
+ if element.has_elements?
+ element.each_element {|child| merge_element!(hash, child) }
+ merge_texts!(hash, element) unless empty_content?(element)
+ hash
+ else
+ merge_texts!(hash, element)
+ end
end
- end
- # Merge all the texts of an element into the hash
- #
- # hash::
- # Hash to add the converted emement to.
- # element::
- # XML element whose texts are to me merged into the hash
- def merge_texts!(hash, element)
- unless element.has_text?
- hash
- else
- # must use value to prevent double-escaping
- merge!(hash, CONTENT_KEY, element.texts.sum(&:value))
+ # Merge all the texts of an element into the hash
+ #
+ # hash::
+ # Hash to add the converted emement to.
+ # element::
+ # XML element whose texts are to me merged into the hash
+ def merge_texts!(hash, element)
+ unless element.has_text?
+ hash
+ else
+ # must use value to prevent double-escaping
+ merge!(hash, CONTENT_KEY, element.texts.sum(&:value))
+ end
end
- end
- # Adds a new key/value pair to an existing Hash. If the key to be added
- # already exists and the existing value associated with key is not
- # an Array, it will be wrapped in an Array. Then the new value is
- # appended to that Array.
- #
- # hash::
- # Hash to add key/value pair to.
- # key::
- # Key to be added.
- # value::
- # Value to be associated with key.
- def merge!(hash, key, value)
- if hash.has_key?(key)
- if hash[key].instance_of?(Array)
- hash[key] << value
+ # Adds a new key/value pair to an existing Hash. If the key to be added
+ # already exists and the existing value associated with key is not
+ # an Array, it will be wrapped in an Array. Then the new value is
+ # appended to that Array.
+ #
+ # hash::
+ # Hash to add key/value pair to.
+ # key::
+ # Key to be added.
+ # value::
+ # Value to be associated with key.
+ def merge!(hash, key, value)
+ if hash.has_key?(key)
+ if hash[key].instance_of?(Array)
+ hash[key] << value
+ else
+ hash[key] = [hash[key], value]
+ end
+ elsif value.instance_of?(Array)
+ hash[key] = [value]
else
- hash[key] = [hash[key], value]
+ hash[key] = value
end
- elsif value.instance_of?(Array)
- hash[key] = [value]
- else
- hash[key] = value
+ hash
end
- hash
- end
- # Converts the attributes array of an XML element into a hash.
- # Returns an empty Hash if node has no attributes.
- #
- # element::
- # XML element to extract attributes from.
- def get_attributes(element)
- attributes = {}
- element.attributes.each { |n,v| attributes[n] = v }
- attributes
- end
+ # Converts the attributes array of an XML element into a hash.
+ # Returns an empty Hash if node has no attributes.
+ #
+ # element::
+ # XML element to extract attributes from.
+ def get_attributes(element)
+ attributes = {}
+ element.attributes.each { |n,v| attributes[n] = v }
+ attributes
+ end
- # Determines if a document element has text content
- #
- # element::
- # XML element to be checked.
- def empty_content?(element)
- element.texts.join.blank?
- end
-end
+ # Determines if a document element has text content
+ #
+ # element::
+ # XML element to be checked.
+ def empty_content?(element)
+ element.texts.join.blank?
+ end
+ end
+end \ No newline at end of file