summaryrefslogtreecommitdiff
path: root/app/models/phone_model.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
commiteaad37485fe59d0306c37cc038dda6d210052910 (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/models/phone_model.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
parentb80bd744ad873f6fc43018bc4bfb90677de167bd (diff)
Merge branch 'develop'
Diffstat (limited to 'app/models/phone_model.rb')
-rw-r--r--app/models/phone_model.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/models/phone_model.rb b/app/models/phone_model.rb
new file mode 100644
index 0000000..e00e0e3
--- /dev/null
+++ b/app/models/phone_model.rb
@@ -0,0 +1,56 @@
+class PhoneModel < ActiveRecord::Base
+ attr_accessible :name, :product_manual_homepage_url, :product_homepage_url, :uuid
+
+ # Associations
+ #
+ belongs_to :manufacturer
+
+ has_many :phones, :dependent => :destroy
+
+ # Validations
+ #
+ validates_presence_of :name
+ validate :validate_product_manual_homepage_url
+ validate :validate_product_homepage_url
+
+ validates_presence_of :uuid
+ validates_uniqueness_of :uuid
+
+ def to_s
+ self.name
+ end
+
+ # State machine:
+ #
+ default_scope where(:state => 'active')
+ state_machine :initial => :active do
+
+ event :deactivate do
+ transition [:active] => :deactivated
+ end
+
+ event :activate do
+ transition [:deactivated] => :active
+ end
+ end
+
+
+ private
+
+ def validate_product_manual_homepage_url
+ if ! self.product_manual_homepage_url.blank?
+ if ! CustomValidators.validate_url( self.product_manual_homepage_url )
+ errors.add( :product_manual_homepage_url, "is invalid." )
+ end
+ end
+ end
+
+ def validate_product_homepage_url
+ if ! self.product_homepage_url.blank?
+ if ! CustomValidators.validate_url( self.product_homepage_url )
+ errors.add( :product_homepage_url, "is invalid." )
+ end
+ end
+ end
+
+end