summaryrefslogtreecommitdiff
path: root/app/models/voicemail_setting.rb
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-26 15:51:35 +0100
committerPeter Kozak <spag@golwen.net>2013-03-26 15:51:35 +0100
commit3833ac1506fb336cd617ec41d25e35c34e74064e (patch)
tree7f865a6529ae42a7e878b34eca8f99b7e65575f2 /app/models/voicemail_setting.rb
parent78948fc995786dcd1beae8e98573ec8ccba3ae9d (diff)
voicemail refactored
Diffstat (limited to 'app/models/voicemail_setting.rb')
-rw-r--r--app/models/voicemail_setting.rb52
1 files changed, 44 insertions, 8 deletions
diff --git a/app/models/voicemail_setting.rb b/app/models/voicemail_setting.rb
index a8bb304..4a9fbc9 100644
--- a/app/models/voicemail_setting.rb
+++ b/app/models/voicemail_setting.rb
@@ -1,12 +1,48 @@
-class VoicemailSetting < ActiveRecord::Base
- self.table_name = 'voicemail_prefs'
- self.primary_key = 'username'
+class VoicemailSetting < ActiveRecord::Base
+ CLASS_TYPES = ['String', 'Integer', 'Boolean']
+ VOICEMAIL_SETTINGS = {
+ 'password' => { :type => 'String', :characters => /[^0-9]/, :input => :password },
+ 'notify' => { :type => 'Boolean', :input => :boolean },
+ 'attachment' => { :type => 'Boolean', :input => :boolean },
+ 'mark_read' => { :type => 'Boolean', :input => :boolean },
+ 'purge' => { :type => 'Boolean', :input => :boolean },
+ 'record_length_max' => { :type => 'Integer', :input => :integer },
+ 'record_length_min' => { :type => 'Integer', :input => :integer },
+ 'records_max' => { :type => 'Integer', :input => :integer },
+ }
- attr_accessible :username, :domain, :name_path, :greeting_path, :password, :notify, :attachment, :mark_read, :purge, :sip_account
+ attr_accessible :voicemail_account_id, :name, :value, :class_type, :description
- has_one :sip_account, :foreign_key => 'auth_name'
+ belongs_to :voicemail_account
- validates_presence_of :username
- validates_presence_of :domain
- validates :username, :uniqueness => {:scope => :domain}
+ validates :name,
+ :presence => true,
+ :uniqueness => {:scope => :voicemail_account_id}
+
+ validates :class_type,
+ :presence => true,
+ :inclusion => { :in => CLASS_TYPES }
+
+ before_validation :set_class_type_and_value
+
+ def to_s
+ name
+ end
+
+ def set_class_type_and_value
+ seting_pref = VOICEMAIL_SETTINGS[self.name]
+ if seting_pref
+ self.class_type = seting_pref[:type]
+ case self.class_type
+ when 'String'
+ if seting_pref[:characters] && self.class_type == 'String'
+ self.value = self.value.to_s.gsub(seting_pref[:characters], '')
+ end
+ when 'Integer'
+ self.value = self.value.to_i
+ when 'Boolean'
+ self.value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(self.value)
+ end
+ end
+ end
end