From 325cb1269cb2aa8e1abe7bc103db3cb47ae5eaf6 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 30 Apr 2006 20:36:37 +0000 Subject: Namespaced OrderedHash so the Rails implementation does not clash with any others. (fixes #4911) [Julian Tarkhanov] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4318 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/calculations.rb | 2 +- .../lib/active_support/ordered_options.rb | 5 +-- railties/CHANGELOG | 2 ++ railties/lib/initializer.rb | 41 ++++++++-------------- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index e16bf9e6d7..409466866f 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -217,7 +217,7 @@ module ActiveRecord 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)] diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 0e97578b3e..1e925145aa 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/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 @@ class OrderedHash < Array #:nodoc: end end -class OrderedOptions < OrderedHash #:nodoc: +class OrderedOptions < ActiveSupport::OrderedHash #:nodoc: def []=(key, value) super(key.to_sym, value) end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 75f4f15e06..0d1d84a61b 100644 --- a/railties/CHANGELOG +++ b/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] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 96144091e8..16f213bc16 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -448,7 +448,7 @@ module Rails 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 @@ module Rails 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 @@ class OrderedHash < Array #:nodoc: 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 @@ class OrderedOptions < OrderedHash #:nodoc: self[name] end end + + private + def find_pair(key) + self.each { |i| return i if i.first == key } + return false + end end \ No newline at end of file -- cgit v1.2.3