foreman/app/models/ptable.rb @ 2d5e52d9
9a55cdc2 | Ohad Levy | # This models the partition tables for a disk layouts
|
|
# It supports both static partition maps and dynamic scripts that create partition tables on-the-fly
|
|||
# A host object may contain a reference to one of these ptables or, alternatively, it may contain a
|
|||
# modified version of one of these in textual form
|
|||
510d53cd | Marek Hulan | class Ptable < Template
|
|
a03e5341 | Marek Hulan | audited
|
|
has_many :audits, :as => :auditable, :class_name => Audited.audit_class.name
|
|||
acfbc458 | Marek Hulan | include Authorizable
|
|
8b737c9c | Joseph Magen | extend FriendlyId
|
|
friendly_id :name
|
|||
053c032d | Tom Caspy | include Parameterizable::ByIdName
|
|
5031bb10 | Tomas Strachota | include ValidateOsFamily
|
|
ca51c513 | Marek Hulan | include DirtyAssociations
|
|
943bc1a2 | Ondrej Prazak | include TaxonomyCollisionFinder
|
|
510d53cd | Marek Hulan | ||
83775e63 | Marek Hulán | class << self
|
|
# we have to override the base_class because polymorphic associations does not detect it correctly, more details at
|
|||
# http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many#1010-Polymorphic-has-many-within-inherited-class-gotcha
|
|||
def base_class
|
|||
self
|
|||
end
|
|||
end
|
|||
self.table_name = 'templates'
|
|||
ff8cc704 | Joseph Mitchell Magen | before_destroy EnsureNotUsedBy.new(:hosts, :hostgroups)
|
|
d7611b24 | Greg Sutcliffe | has_many_hosts
|
|
7d993b41 | Joseph Mitchell Magen | has_many :hostgroups
|
|
741bd717 | Daniel Lobato | has_and_belongs_to_many :operatingsystems, :join_table => :operatingsystems_ptables, :association_foreign_key => :operatingsystem_id, :foreign_key => :ptable_id
|
|
f2c78d4a | Joseph Magen | validates :layout, :presence => true
|
|
510d53cd | Marek Hulan | validates :name, :uniqueness => true
|
|
5031bb10 | Tomas Strachota | validate_inclusion_in_families :os_family
|
|
66bb73ba | Ohad Levy | ||
510d53cd | Marek Hulan | # these can't be shared in parent class, scoped search can't handle STI properly
|
|
# tested with scoped_search 3.2.0
|
|||
include Taxonomix
|
|||
2d5e52d9 | Ondřej Pražák | include TemplateTax
|
|
510d53cd | Marek Hulan | scoped_search :on => :name, :complete_value => true, :default_order => true
|
|
scoped_search :on => :locked, :complete_value => {:true => true, :false => false}
|
|||
scoped_search :on => :snippet, :complete_value => {:true => true, :false => false}
|
|||
scoped_search :on => :template
|
|||
c2aa6cf8 | Sean O'Keeffe | scoped_search :on => :vendor, :only_explicit => true, :complete_value => true
|
|
scoped_search :on => :default, :only_explicit => true, :complete_value => {:true => true, :false => false}
|
|||
510d53cd | Marek Hulan | ||
scoped_search :on => :template, :complete_value => false, :rename => 'layout'
|
|||
scoped_search :on => :os_family, :rename => 'family', :complete_value => :true
|
|||
alias_attribute :layout, :template
|
|||
2d5e52d9 | Ondřej Pražák | attr_exportable :os_family, taxonomy_exportable
|
|
404ead2a | Marek Hulan | ||
ca51c513 | Marek Hulan | dirty_has_many_associations :operatingsystems
|
|
510d53cd | Marek Hulan | # with proc support, default_scope can no longer be chained
|
|
# include all default scoping here
|
|||
default_scope lambda {
|
|||
with_taxonomy_scope do
|
|||
order("#{Template.table_name}.name")
|
|||
end
|
|||
}
|
|||
def self.template_includes
|
|||
super + [:operatingsystems]
|
|||
e2d3654e | Joseph Mitchell Magen | end
|
|
de9e7ada | Marek Hulan | ||
9ca77d08 | Timo Goebel | def self.preview_host_collection
|
|
de9e7ada | Marek Hulan | super.where(:managed => true)
|
|
end
|
|||
5908bf41 | Dominic Cleal | ||
def taxonomy_foreign_conditions
|
|||
{ :ptable_id => id }
|
|||
end
|
|||
ca51c513 | Marek Hulan | ||
private
|
|||
def import_custom_data(options)
|
|||
import_oses(options)
|
|||
self.os_family = self.operatingsystems.first.family if self.operatingsystem_ids.present?
|
|||
end
|
|||
9a55cdc2 | Ohad Levy | end
|