@@ -6,6 +6,7 @@ class Operatingsystem < ApplicationRecord
66 include Authorizable
77 include ValidateOsFamily
88 include PxeLoaderSupport
9+ include OperatingSystemNaming
910 extend FriendlyId
1011 friendly_id :title
1112
@@ -95,10 +96,6 @@ class Jail < Safemode::Jail
9596 allow :id , :name , :major , :minor , :family , :to_s , :== , :release , :release_name , :kernel , :initrd , :pxe_type , :boot_files_uri , :password_hash , :mediumpath , :bootfile
9697 end
9798
98- def self . title_name
99- "title" . freeze
100- end
101-
10299 def additional_media ( medium_provider )
103100 medium_provider . additional_media . map ( &:with_indifferent_access )
104101 end
@@ -141,8 +138,7 @@ def self.families_as_collection
141138
142139 # The OS is usually represented as the concatenation of the OS and the revision
143140 def to_label
144- return description if description . present?
145- fullname
141+ self . class . to_label ( description : description , name : name , major : major , minor : minor )
146142 end
147143
148144 # to_label setter updates description and does not try to parse and update major, minor attributes
@@ -155,40 +151,17 @@ def to_param
155151 end
156152
157153 def release
158- " #{ major } #{ ( '.' + minor . to_s ) if minor . present? } "
154+ self . class . release ( major : major , minor : minor )
159155 end
160156
161157 def fullname
162- " #{ name } #{ release } "
158+ self . class . fullname ( name : name , major : major , minor : minor )
163159 end
164160
165161 def to_s
166162 fullname
167163 end
168164
169- def self . find_by_to_label ( str )
170- os = find_by_description ( str . to_s )
171- return os if os
172- name , version = str . split ( " " )
173- cond = { :name => name }
174- if version
175- ( major , minor ) = os_major_minor_from_version_str ( name , version )
176- cond [ :major ] = major if major
177- cond [ :minor ] = minor if minor
178- end
179- find_by ( cond )
180- end
181-
182- def self . os_major_minor_from_version_str ( os_name , version_str )
183- if os_name == 'Ubuntu'
184- x , y , minor = version_str . split ( '.' , 3 )
185- major = "#{ x } .#{ y } "
186- else
187- major , minor = version_str . split ( '.' )
188- end
189- [ major , minor ]
190- end
191-
192165 # Implemented only in the OSs subclasses where it makes sense
193166 def available_loaders
194167 [ "None" , "PXELinux BIOS" ]
@@ -384,7 +357,7 @@ def set_family
384357 end
385358
386359 def set_title
387- self . title = to_label . to_s [ 0 .. 254 ]
360+ self . title = self . class . generate_title ( description : description , name : name , major : major , minor : minor )
388361 end
389362
390363 def stringify_major_and_minor
0 commit comments