Project

General

Profile

« Previous | Next » 

Revision 95a66717

Added by Marek Hulán over 10 years ago

Fixes #3962 - Refactor class overwriting

View differences:

app/controllers/operatingsystems_controller.rb
@operatingsystem.os_default_templates.build(:template_kind_id => kind)
end
end if SETTINGS[:unattended]
@operatingsystem = generalize(@operatingsystem)
end
def update
......
else
process_error
end
@operatingsystem = generalize(@operatingsystem)
end
def destroy
......
@operatingsystem = Operatingsystem.find(params[:id])
end
def generalize(os)
os.becomes(Operatingsystem).tap { |o| o.type = os.type }
end
end
app/models/concerns/authorization.rb
# We get called again with the operation being set to create
return true if operation == "edit" and new_record?
klass = self.class.name.downcase
klasses = self.class.name.tableize
if self.class < Operatingsystem
klass = 'operatingsystem'
klasses = 'operatingsystems'
else
klass = self.class.name.downcase
klasses = self.class.name.tableize
end
#TODO: Extract all fo the specific implementations into each individual class
klasses.gsub!(/auth_source.*/, "authenticators")
klasses.gsub!(/common_parameters.*/, "global_variables")
app/models/operatingsystems/archlinux.rb
medium_uri(host).to_s
end
# Override the class representation, as this breaks many rails helpers
def class
Operatingsystem
end
def pxe_type
"aif"
end
......
"Arch Linux"
end
def self.model_name
superclass.model_name
end
end
app/models/operatingsystems/debian.rb
medium_uri(host).select(:path, :query).compact.join('?')
end
# Override the class representation, as this breaks many rails helpers
def class
Operatingsystem
end
def boot_files_uri(medium, architecture)
raise ::Foreman::Exception.new(N_("invalid medium for %s"), to_s) unless media.include?(medium)
raise ::Foreman::Exception.new(N_("invalid architecture for %s"), to_s) unless architectures.include?(architecture)
......
name =~ /ubuntu/i ? "ubuntu" : "debian"
end
def self.model_name
superclass.model_name
end
end
app/models/operatingsystems/freebsd.rb
medium_uri(host).to_s
end
def class
Operatingsystem
end
def pxe_type
"memdisk"
end
......
"boot/FreeBSD-#{arch}-#{release}-mfs.img"
end
def self.model_name
superclass.model_name
end
def display_family
"FreeBSD"
end
app/models/operatingsystems/gentoo.rb
def mediumpath host
end
def class
Operatingsystem
end
def pxe_type
end
......
def display_family
"Gentoo"
end
def self.model_name
superclass.model_name
end
end
app/models/operatingsystems/redhat.rb
end
end
# Override the class representation, as this breaks many rails helpers
def class
Operatingsystem
end
# The PXE type to use when generating actions and evaluating attributes. jumpstart, kickstart and preseed are currently supported.
def pxe_type
"kickstart"
......
s.strip!
s.blank? ? description : s
end
def self.model_name
superclass.model_name
end
end
app/models/operatingsystems/solaris.rb
def jumpstart_path medium, domain
resolv_nfs_path medium.jumpstart_host, medium.jumpstart_dir, domain
end
# Override the class representation, as this breaks many rails helpers
def class
Operatingsystem
end
# Does this OS family support a build variant that is constructed from a prebuilt archive
def supports_image
......
"Solaris"
end
def self.model_name
superclass.model_name
end
private
def resolv_nfs_path host, dir, domain
host = host + ".#{domain.name}" unless host =~ /\./
app/models/operatingsystems/suse.rb
PXEFILES = {:kernel => "linux", :initrd => "initrd"}
# Override the class representation, as this breaks many rails helpers
def class
Operatingsystem
end
def pxe_type
"yast"
end
......
def display_family
"SUSE"
end
def self.model_name
superclass.model_name
end
end
app/models/operatingsystems/windows.rb
class Windows < Operatingsystem
PXEFILES = {:kernel => "startrom.0", :initrd => "boot.sdi"}
def class
Operatingsystem
end
def pxe_type
"waik"
end
......
pxedir + "/" + PXEFILES[file]
end
def self.model_name
superclass.model_name
end
def display_family
"Windows"
end
test/unit/suse_test.rb
class SuseTest < ActiveSupport::TestCase
test "ruby class should be OS" do
assert_equal Operatingsystem, Suse.first.class
end
test "os label for suse" do
assert_equal "OpenSuse 11.4", operatingsystems(:suse).to_label
end

Also available in: Unified diff