aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mauve/alert.rb')
-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