/
crosstab_object.rb
60 lines (56 loc) · 2.05 KB
/
crosstab_object.rb
1
2
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
################################################################################
#This file is part of Dedomenon.
#
#Dedomenon is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#Dedomenon is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Affero General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with Dedomenon. If not, see <http://www.gnu.org/licenses/>.
#
#Copyright 2008 Raphaël Bauduin
################################################################################
# This class only exists to access its connection as in
# CrosstabObject.connection.quote_string(params["#{@list_id}_order"].to_s)
#
class CrosstabObject < ActiveRecord::Base
# FIXME: we map it to the details table, but we'll never use it.
def self.table_name
"details"
end
# FIXME: we map it but it's never used I think.
def self.inheritance_column
"crosstab_inheritance_column"
end
# def self.serialize_columns(a)
# a.each do |c|
# m = %{ def #{c}
# str = read_attribute(:#{c})
# return "" if str.nil?
# end }
# self.class_eval(m)
# end
# end
def self.define_accessors(all_details, serialized)
all_details.each do |c|
m = %{ def #{c.madb_sanitize}
str = self.attributes[#{c.dump}]
}
if serialized.include?(c)
m+= %{ return "" if str.nil?
return YAML.load(str)
}
end
#{serialized.include?(c) ? "return YAML.load(str)" : "return str"}
m+=" end "
#{serialized.include?(c) ? "puts 'return emtpy string' and return "" if str.nil?; return YAML.load(str)" : "return str"}
self.class_eval(m)
end
end
end