37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/property/attribute.rb', line 37
def store_properties_in(accessor)
if accessor.nil? || accessor == self
accessor = ''
else
accessor = "#{accessor}."
end
load_and_dump_methods =<<-EOF
private
def load_properties
raw_data = #{accessor}read_attribute('properties')
prop = raw_data ? decode_properties(raw_data) : Properties.new
# We need to set the owner to access property definitions and enable
# type casting on write.
prop.owner = self
prop
end
def dump_properties
if @properties && @properties.changed?
if [email protected]?
#{accessor}write_attribute('properties', encode_properties(@properties))
else
#{accessor}write_attribute('properties', nil)
end
@properties.clear_changes!
end
true
end
EOF
class_eval(load_and_dump_methods, __FILE__, __LINE__)
end
|