summaryrefslogtreecommitdiff
path: root/app/models/phone_model.rb
diff options
context:
space:
mode:
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