lib/has_settings/setting.rb in has_settings-0.0.4 vs lib/has_settings/setting.rb in has_settings-0.0.5

- old
+ new

@@ -1,11 +1,12 @@ module HasSettings class Setting < ActiveRecord::Base abstract_class = true - after_create :reset_owner_association - after_destroy :reset_owner_association + after_create :reset_owner_association + after_destroy :reset_owner_association + validate :validate_format_of_name def create if new_record? super end @@ -32,9 +33,17 @@ def protected? self.class.protected?(self.name.to_sym) end private + + def validate_format_of_name + if name.blank? + errors.add(:name, :blank) + elsif !name.is_a?(String) || name !~ /^([a-z0-9]+_?)+$/ + errors.add(:name, :invalid) + end + end def owner_class_instance send(self.class.owner_class_sym) end