3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/config_find_all_as_tree.rb', line 3
def find_all_as_tree
returning(ActiveSupport::OrderedHash.new) do |result|
db_key = (ActiveRecord::Base.connection.adapter_name.downcase == 'mysql' ? '`key`' : 'key')
find(:all, :order => db_key).each do |setting|
path = setting.key.split('.')
current_level = result
path.each do |path_element|
if path_element.equal?(path.last)
current_level[path_element] = setting
else
current_level[path_element] ||= ActiveSupport::OrderedHash.new
current_level = current_level[path_element]
end
end end end end
|