mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
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
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 @@ 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,32 +589,12 @@ class OrderedHash < Array #:nodoc:
|
||||
self << [key, value]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def [](key)
|
||||
pair = find_pair(key)
|
||||
pair = find_pair(key.to_sym)
|
||||
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)
|
||||
end
|
||||
|
||||
def method_missing(name, *args)
|
||||
if name.to_s =~ /(.*)=$/
|
||||
self[$1.to_sym] = args.first
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user