Sha256: 81074b1420391556850e7e48f7f1fe69682398ef16822ee203c743f94557ccc5

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Nucleus
  module VendorParser
    extend Nucleus::Logging

    # Get a parsed vendor instance from the adapter_config file
    #
    # @param [File, String, Path] adapter_config path to the adapter configuration file to be parsed
    # @return [Nucleus::Vendor] the parsed Vendor instance
    def self.parse(adapter_config)
      schema_file = "#{Nucleus.root}/schemas/api.adapter.schema.yml"
      schema = Kwalify::Yaml.load_file(schema_file, untabify: true, preceding_alias: true)
      validator = Kwalify::Validator.new(schema)
      config_parser = Kwalify::Yaml::Parser.new(validator, data_binding: true, preceding_alias: true)

      vendor = config_parser.parse_file(adapter_config)
      errors = config_parser.errors
      # show errors
      if errors && !errors.empty?
        errors.each do |e|
          log.error "[#{e.path}] #{e.message}"
        end
      end
      # vendor is not valid and shall not be returned
      return nil if errors && !errors.empty?
      vendor
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nucleus-0.3.1 lib/nucleus/core/import/vendor_parser.rb
nucleus-0.2.0 lib/nucleus/core/import/vendor_parser.rb
nucleus-0.1.0 lib/nucleus/core/import/vendor_parser.rb