Permalink
Browse files

Namespaced OrderedHash so the Rails implementation does not clash wit…

…h any others. (fixes #4911) [Julian Tarkhanov]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4318 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 59bd658 commit 325cb1269cb2aa8e1abe7bc103db3cb47ae5eaf6 @technoweenie technoweenie committed Apr 30, 2006
@@ -217,7 +217,7 @@ def execute_grouped_calculation(operation, column_name, column, options) #:nodoc
key_records = key_records.inject({}) { |hsh, r| hsh.merge(r.id => r) }
end
- calculated_data.inject(OrderedHash.new) do |all, row|
+ calculated_data.inject(ActiveSupport::OrderedHash.new) do |all, row|
key = associated ? key_records[row[group_alias].to_i] : type_cast_calculated_value(row[group_alias], group_column)
value = row[aggregate_alias]
all << [key, type_cast_calculated_value(value, column, operation)]
@@ -1,4 +1,5 @@
-class OrderedHash < Array #:nodoc:
+# OrderedHash is namespaced to prevent conflicts with other implementations
+class ActiveSupport::OrderedHash < Array #:nodoc:
def []=(key, value)
if pair = find_pair(key)
pair.pop
@@ -24,7 +25,7 @@ def find_pair(key)
end
end
-class OrderedOptions < OrderedHash #:nodoc:
+class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
def []=(key, value)
super(key.to_sym, value)
end
View
@@ -1,5 +1,7 @@
*SVN*
+* Namespaced OrderedHash so the Rails implementation does not clash with any others. (fixes #4911) [Julian Tarkhanov]
+
* Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.]
* Added script/process/inspector to do simple process status information on Rails dispatchers keeping pid files in tmp/pids [DHH]
@@ -448,7 +448,7 @@ def initialize
self.database_configuration_file = default_database_configuration_file
for framework in default_frameworks
- self.send("#{framework}=", OrderedOptions.new)
+ self.send("#{framework}=", Rails::OrderedOptions.new)
end
end
@@ -576,40 +576,23 @@ def default_plugin_paths
end
# Needs to be duplicated from Active Support since its needed before Active
-# Support is available.
-class OrderedHash < Array #:nodoc:
- def []=(key, value)
+# Support is available. Here both Options and Hash are namespaced to prevent
+# conflicts with other implementations AND with the classes residing in ActiveSupport.
+class Rails::OrderedOptions < Array #:nodoc:
+ def []=(key, value)
+ key = key.to_sym
+
if pair = find_pair(key)
pair.pop
pair << value
else
self << [key, value]
end
end
-
- def [](key)
- pair = find_pair(key)
- pair ? pair.last : nil
- end
-
- def keys
- self.collect { |i| i.first }
- end
- private
- def find_pair(key)
- self.each { |i| return i if i.first == key }
- return false
- end
-end
-
-class OrderedOptions < OrderedHash #:nodoc:
- def []=(key, value)
- super(key.to_sym, value)
- end
-
def [](key)
- super(key.to_sym)
+ pair = find_pair(key.to_sym)
+ pair ? pair.last : nil
end
def method_missing(name, *args)
@@ -619,4 +602,10 @@ def method_missing(name, *args)
self[name]
end
end
+
+ private
+ def find_pair(key)
+ self.each { |i| return i if i.first == key }
+ return false
+ end
end

0 comments on commit 325cb12

Please sign in to comment.