Class: PackerFiles::Finder
- Inherits:
-
Object
- Object
- PackerFiles::Finder
- Defined in:
- lib/PackerFiles/OS/Finder.rb
Instance Method Summary collapse
-
#class_name(os_name, version = nil) ⇒ Object
Return the correct class name that matches the given OS name and Version.
-
#class_names ⇒ Object
Return the list of OSes that can be found by the finder.
-
#initialize ⇒ Finder
constructor
Dummy constructor.
Constructor Details
#initialize ⇒ Finder
Dummy constructor
10 11 |
# File 'lib/PackerFiles/OS/Finder.rb', line 10 def initialize end |
Instance Method Details
#class_name(os_name, version = nil) ⇒ Object
Return the correct class name that matches the given OS name and Version
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/PackerFiles/OS/Finder.rb', line 15 def class_name(os_name, version=nil) generic = [] specific = [] load_file_list(os_name) class_list(os_name).each do |cl| if !cl.respond_to? :versions next elsif cl.name.gsub('PackerFiles::','') != os_name next elsif cl.versions.empty? generic.push(cl) else specific.push(cl) if cl.versions.index(version) end end return specific.first if !specific.empty? return generic.first if !generic.empty? raise NotImplementedError.new(os_name) end |
#class_names ⇒ Object
Return the list of OSes that can be found by the finder.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/PackerFiles/OS/Finder.rb', line 36 def class_names # Get list of directories under OS folder. We can find # files to load from this location. classes = PackerFiles.DirPath("OS/*/").map {|dir| Dir.glob(File.join(dir, '*.rb')) { |filename| load(filename) } begin class_list(File.basename(dir)) rescue NotImplementedError nil end } classes.flatten.keep_if {|cl| cl.respond_to? :versions} end |