summaryrefslogtreecommitdiff
path: root/app/models/hunt_group.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/hunt_group.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'app/models/hunt_group.rb')
-rw-r--r--app/models/hunt_group.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/models/hunt_group.rb b/app/models/hunt_group.rb
new file mode 100644
index 0000000..276ae53
--- /dev/null
+++ b/app/models/hunt_group.rb
@@ -0,0 +1,43 @@
+class HuntGroup < ActiveRecord::Base
+ attr_accessible :name, :strategy, :seconds_between_jumps, :phone_numbers_attributes
+
+ belongs_to :tenant
+ has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy
+
+ validates_uniqueness_of :name, :scope => :tenant_id,
+ :allow_nil => true, :allow_blank => true
+
+ validates_presence_of :strategy
+ validates_inclusion_of :strategy, :in => HUNT_GROUP_STRATEGIES
+
+ validates_presence_of :seconds_between_jumps,
+ :if => Proc.new{ |hunt_group| hunt_group.strategy != 'ring_all' }
+ validates_numericality_of :seconds_between_jumps,
+ :only_integer => true,
+ :greater_than_or_equal_to => VALID_SECONDS_BETWEEN_JUMPS_VALUES.min,
+ :less_than_or_equal_to => VALID_SECONDS_BETWEEN_JUMPS_VALUES.max,
+ :if => Proc.new{ |hunt_group| hunt_group.strategy != 'ring_all' }
+ validates_inclusion_of :seconds_between_jumps,
+ :in => VALID_SECONDS_BETWEEN_JUMPS_VALUES,
+ :if => Proc.new{ |hunt_group| hunt_group.strategy != 'ring_all' }
+ validates_inclusion_of :seconds_between_jumps,
+ :in => [nil],
+ :if => Proc.new{ |hunt_group| hunt_group.strategy == 'ring_all' }
+
+ validates_presence_of :uuid
+ validates_uniqueness_of :uuid
+
+ has_many :hunt_group_members, :dependent => :destroy, :order => :position
+
+ has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy
+ accepts_nested_attributes_for :phone_numbers,
+ :reject_if => lambda { |phone_number| phone_number[:number].blank? },
+ :allow_destroy => true
+
+ has_many :hunt_group_members, :dependent => :destroy
+
+ def to_s
+ self.name || I18n.t('hunt_groups.name') + ' ID ' + self.id.to_s
+ end
+
+end