220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/go_secure.rb', line 220
def secure_serialize(column)
raise "only one secure column per record! (yes I'm lazy)" if self.respond_to?(:secure_column) && self.secure_column
cattr_accessor :secure_column
cattr_accessor :more_before_saves
self.secure_column = column
prepend SecureSerializeHelpers
before_save :persist_secure_object
define_singleton_method(:before_save) do |*args|
raise "only simple before_save calls after secure_serialize: #{args.to_json}" unless args.length == 1 && args[0].is_a?(Symbol)
self.more_before_saves ||= []
self.more_before_saves << args[0]
end
define_method("secure_column_value") do
nil
end
define_method("#{column}") do
load_secure_object unless @loaded_secure_object
@secure_object
end
define_method("#{column}=") do |val|
@loaded_secure_object = true
@secure_object = val
end
end
|