Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 325cb1269cb2aa8e1abe7bc103db3cb47ae5eaf6 1 parent 59bd658
@technoweenie technoweenie authored
View
2  activerecord/lib/active_record/calculations.rb
@@ -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)]
View
5 activesupport/lib/active_support/ordered_options.rb
@@ -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
2  railties/CHANGELOG
@@ -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]
View
41 railties/lib/initializer.rb
@@ -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,9 +576,12 @@ 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
@@ -586,30 +589,10 @@ def []=(key, value)
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
Please sign in to comment.
Something went wrong with that request. Please try again.