aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-12-12 10:34:09 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-12-12 10:34:09 +0000
commitac2fb2330a564ba52761ed2b06036c61fc9f07d6 (patch)
tree466e535bdb1ddd27e8fcf6c51aa9cbf6418e613c /lib/mauve
parent5e60f5a53b669ef4f1dcc0d90bea8a6b6e80d5ce (diff)
Added field truncation + warning logs.
Diffstat (limited to 'lib/mauve')
-rw-r--r--lib/mauve/alert.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 3307b59..9d04250 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -118,7 +118,8 @@ module Mauve
has 1, :alert_earliest_date
before :valid?, :do_set_timestamps
- before :save, :do_sanitize_html
+ before :valid?, :do_truncate_fields
+ before :save, :do_sanitize_html
after :destroy, :destroy_associations
@@ -264,6 +265,25 @@ module Mauve
end
end
+ #
+ # This truncates strings to their maximum allowed length.
+ #
+ def do_truncate_fields
+ attributes.each do |key, val|
+ prop = self.class.properties[key]
+ next unless prop.is_a?(DataMapper::Property::String)
+
+ #
+ # Truncate
+ #
+ max_length = prop.length
+ if val.length > max_length
+ logger.warn "#{self.to_s} truncating #{key} to #{max_length} chars"
+ attribute_set(key, val[0...max_length])
+ end
+ end
+ end
+
def do_set_timestamps(context = :default)
self.updated_at = Time.now if self.dirty?
end