summaryrefslogtreecommitdiff
path: root/app/models/manufacturer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/manufacturer.rb')
-rw-r--r--app/models/manufacturer.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/models/manufacturer.rb b/app/models/manufacturer.rb
new file mode 100644
index 0000000..03d2bb7
--- /dev/null
+++ b/app/models/manufacturer.rb
@@ -0,0 +1,46 @@
+class Manufacturer < ActiveRecord::Base
+ attr_accessible :name, :ieee_name, :homepage_url
+
+ # Associations:
+ #
+ has_many :ouis, :dependent => :destroy
+ has_many :phone_models, :order => :name, :dependent => :destroy
+
+
+ # Validations:
+ #
+ validates_presence_of :name
+ validates_presence_of :ieee_name
+
+ validates_uniqueness_of :name, :case_sensitive => false
+
+ validate :validate_homepage_url
+
+ # State Machine stuff
+ default_scope where(:state => 'active').order(:name)
+ state_machine :initial => :active do
+
+ event :deactivate do
+ transition [:active] => :deactivated
+ end
+
+ event :activate do
+ transition [:deactivated] => :active
+ end
+ end
+
+ def to_s
+ self.name
+ end
+
+ private
+
+ def validate_homepage_url
+ if ! self.homepage_url.blank?
+ if ! CustomValidators.validate_url( self.homepage_url )
+ errors.add( :homepage_url, "is invalid." )
+ end
+ end
+ end
+
+end