summaryrefslogtreecommitdiff
path: root/app/models/phone_book.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/models/phone_book.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'app/models/phone_book.rb')
-rw-r--r--app/models/phone_book.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/phone_book.rb b/app/models/phone_book.rb
new file mode 100644
index 0000000..3603eae
--- /dev/null
+++ b/app/models/phone_book.rb
@@ -0,0 +1,33 @@
+class PhoneBook < ActiveRecord::Base
+ attr_accessible :name, :description, :uuid
+
+ belongs_to :phone_bookable, :polymorphic => true
+ has_many :phone_book_entries, :dependent => :destroy
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => [ :phone_bookable_type, :phone_bookable_id ]
+
+ validates_length_of :name, :within => 1..50
+
+ validates_presence_of :uuid
+ validates_uniqueness_of :uuid
+
+ # State Machine stuff
+ default_scope where(:state => 'active')
+ state_machine :initial => :active do
+ end
+
+ def to_s
+ name
+ end
+
+ def find_entry_by_number(number)
+ phone_book_entries_ids = self.phone_book_entries.map{|phone_book_entry| phone_book_entry.id}
+
+ phone_number = PhoneNumber.where(:phone_numberable_id => phone_book_entries_ids, :phone_numberable_type => 'PhoneBookEntry', :number => number).first
+
+ if phone_number
+ return phone_number.phone_numberable
+ end
+ end
+end