Class | BoxGrinder::ApplianceDefinitionHelper |
In: |
lib/boxgrinder-core/helpers/appliance-definition-helper.rb
lib/boxgrinder-core/helpers/appliance-definition-helper.rb |
Parent: | Object |
appliance_configs | [R] | |
appliance_configs | [R] | |
appliance_parser | [R] | |
appliance_parser | [R] |
# File lib/boxgrinder-core/helpers/appliance-definition-helper.rb, line 25 25: def initialize(options = {}) 26: @log = options[:log] || LogHelper.new 27: @appliance_configs = [] 28: @appliance_parser = ApplianceParser.new(:log => @log) 29: end
# File lib/boxgrinder-core/helpers/appliance-definition-helper.rb, line 25 25: def initialize(options = {}) 26: @log = options[:log] || LogHelper.new 27: @appliance_configs = [] 28: @appliance_parser = ApplianceParser.new(:log => @log) 29: end
Reads definition provided as string. This string can be a YAML document. In this case definition is parsed and an ApplianceConfig object is returned. In other cases it tries to search for a file with provided name.
# File lib/boxgrinder-core/helpers/appliance-definition-helper.rb, line 37 37: def read_definitions(definition, content_type = nil) 38: @appliance_parser.load_schemas 39: if File.exists?(definition) 40: definition_file_extension = File.extname(definition) 41: 42: appliance_config = 43: case definition_file_extension 44: when '.appl', '.yml', '.yaml' 45: @appliance_parser.parse_definition(definition) 46: else 47: unless content_type.nil? 48: case content_type 49: when 'application/x-yaml', 'text/yaml' 50: @appliance_parser.parse_definition(definition) 51: end 52: end 53: end 54: 55: return if appliance_config.nil? 56: 57: @appliance_configs << appliance_config 58: appliances = [] 59: 60: @appliance_configs.each { |config| appliances << config.name } 61: 62: appliance_config.appliances.reverse.each do |appliance_name| 63: read_definitions("#{File.dirname(definition)}/#{appliance_name}#{definition_file_extension}") unless appliances.include?(appliance_name) 64: end unless appliance_config.appliances.nil? or !appliance_config.appliances.is_a?(Array) 65: else 66: # Assuming that the definition is provided as string 67: @appliance_configs << @appliance_parser.parse_definition(definition, false) 68: end 69: end
Reads definition provided as string. This string can be a YAML document. In this case definition is parsed and an ApplianceConfig object is returned. In other cases it tries to search for a file with provided name.
# File lib/boxgrinder-core/helpers/appliance-definition-helper.rb, line 37 37: def read_definitions(definition, content_type = nil) 38: @appliance_parser.load_schemas 39: if File.exists?(definition) 40: definition_file_extension = File.extname(definition) 41: 42: appliance_config = 43: case definition_file_extension 44: when '.appl', '.yml', '.yaml' 45: @appliance_parser.parse_definition(definition) 46: else 47: unless content_type.nil? 48: case content_type 49: when 'application/x-yaml', 'text/yaml' 50: @appliance_parser.parse_definition(definition) 51: end 52: end 53: end 54: 55: return if appliance_config.nil? 56: 57: @appliance_configs << appliance_config 58: appliances = [] 59: 60: @appliance_configs.each { |config| appliances << config.name } 61: 62: appliance_config.appliances.reverse.each do |appliance_name| 63: read_definitions("#{File.dirname(definition)}/#{appliance_name}#{definition_file_extension}") unless appliances.include?(appliance_name) 64: end unless appliance_config.appliances.nil? or !appliance_config.appliances.is_a?(Array) 65: else 66: # Assuming that the definition is provided as string 67: @appliance_configs << @appliance_parser.parse_definition(definition, false) 68: end 69: end