From b80bd744ad873f6fc43018bc4bfb90677de167bd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 17 Dec 2012 12:01:45 +0100 Subject: Start of GS5. --- app/models/manufacturer.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 app/models/manufacturer.rb (limited to 'app/models/manufacturer.rb') 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 -- cgit v1.2.3