30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/kortype.rb', line 30
def kortype *attrs
if Hash === attrs[-1]
options = {}
attrs.delete_at(-1).each do |key, value|
options[key.to_sym] = value
end
else
options = {}
end
type = options.delete :type
raise ArgumentError.new, 'must set the attribute type' unless type
attrs.map!(&:to_sym)
attrs.each do |attr|
kortype_columns[attr] = Kortype::Type.new attr, type, options
class_eval do
define_method attr do
self.kortype_columns[attr].value
end
define_method "#{attr}=" do |value|
self.kortype_columns[attr].value = value
end
end
end
end
|