Project

General

Profile

Download (1.41 KB) Statistics
| Branch: | Tag: | Revision:
286a2207 Ohad Levy
class Operatingsystem < ActiveRecord::Base
9eb0e160 Ohad Levy
has_many :hosts
286a2207 Ohad Levy
has_many :medias
c6eee281 Ohad Levy
has_and_belongs_to_many :ptables
ffc12fd6 Ohad Levy
has_and_belongs_to_many :architectures
c6eee281 Ohad Levy
has_and_belongs_to_many :puppetclasses
286a2207 Ohad Levy
validates_presence_of :major, :message => "Operating System version is required"
c4c59fbb Ohad Levy
validates_presence_of :name
8123c475 Lucas Tolchinsky
validates_numericality_of :major
3d29a5a4 Lucas Tolchinsky
validates_numericality_of :minor, :allow_nil => true
validates_format_of :name, :with => /\A(\S+)\Z/, :message => "can't be blank or contain white spaces."
9a9b3e75 Paul Kelly
before_validation :downcase_release_name
c5ea5361 Ohad Levy
#TODO: add validation for name and major uniqueness
286a2207 Ohad Levy
88693384 Lucas Tolchinsky
before_destroy Ensure_not_used_by.new(:hosts)
611397af Ohad Levy
acts_as_audited
286a2207 Ohad Levy
5f75dccc Paul Kelly
# Emulate multiple inheritance from a virtual Family class
def after_initialize
extend eval("Family::#{Family::FAMILIES[family_id]}") if family_id
end

def family
end

def family= value
if index = Family::FAMILIES.index(value.to_sym)
update_attribute(:family_id, index)
else
raise RuntimeError, "Unable to find family [#{value}]"
end
end

286a2207 Ohad Levy
# The OS is usually represented as the catenation of the OS and the revision. E.G. "Solaris 10"
def to_label
"#{name} #{major}#{('.' + minor) unless minor.empty?}"
end

290c4d84 Ohad Levy
def to_s
to_label
end

3312a03d Ohad Levy
def fullname
c289176c Ohad Levy
to_label
3312a03d Ohad Levy
end
5f75dccc Paul Kelly
9a9b3e75 Paul Kelly
private
def downcase_release_name
2e31dbca Ohad Levy
self.release_name.downcase! unless defined?(Rake) or release_name.nil? or release_name.empty?
9a9b3e75 Paul Kelly
end

286a2207 Ohad Levy
end