Sha256: 982f749dc321107def55e8171f0c98b74783b36c7a1b391fce2d06308bf212ed

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

module Specinfra
  class HostInventory
    class ParserFactory
      def self.instance
        self.new(os)
      end

      def initialize(os_info)
        @os_info = os_info
      end

      def get(resource_type)
        create_parser_class(resource_type)
      end

      private

      def create_parser_class(resource_type)
        family = @os_info[:family]
        version = @os_info[:release] ? "V#{@os_info[:release].to_i}" : nil
        common_class = Specinfra::HostInventory::Parser
        base_class = common_class.const_get('Base')
        begin
          os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
        rescue
          parser_class = base_class.const_get(resource_type.to_camel_case)
          return parser_class.create(Specinfra.backend)
        end

        if family && version
          begin
            version_class = os_class.const_get(version)
          rescue
            version_class = os_class.const_get('Base')
          end
        elsif family.nil?
          version_class = os_class
        elsif family != 'base' && version.nil?
          version_class = os_class.const_get('Base')
        end

        begin
          parser_class = version_class.const_get(resource_type.to_camel_case)
        rescue
          version_class = os_class.const_get('Base')
          parser_class = version_class.const_get(resource_type.to_camel_case)
        end

        parser_class.create(Specinfra.backend)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
koma-0.17.0 lib/koma/ext/specinfra/host_inventory/parser_factory.rb
koma-0.16.0 lib/koma/ext/specinfra/host_inventory/parser_factory.rb
koma-0.15.0 lib/koma/ext/specinfra/host_inventory/parser_factory.rb