Project

General

Profile

Download (777 Bytes) Statistics
| Branch: | Tag: | Revision:
086ec942 Ohad Levy
class Hostgroup < ActiveRecord::Base
has_and_belongs_to_many :puppetclasses
validates_uniqueness_of :name
9d5bb4fd Lucas Tolchinsky
validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces."
aa1796f3 Paul Kelly
has_many :group_parameters, :dependent => :destroy, :foreign_key => :reference_id
bd46fa41 Ohad Levy
accepts_nested_attributes_for :group_parameters, :reject_if => lambda { |a| a[:value].blank? }, :allow_destroy => true
086ec942 Ohad Levy
has_many :hosts
17a015c2 Ohad Levy
before_destroy Ensure_not_used_by.new(:hosts)
b09b4515 Ohad Levy
default_scope :order => 'name'
086ec942 Ohad Levy
611397af Ohad Levy
acts_as_audited
086ec942 Ohad Levy
#TODO: add a method that returns the valid os for a hostgroup

b09b4515 Ohad Levy
def all_puppetclasses
puppetclasses
end

def hostgroup
self
end

66d71c0b Ohad Levy
def as_json(options={})
super({:only => [:name, :id]}.merge(options))
end

086ec942 Ohad Levy
end