Sha256: 17fc5fc362e268539a80a9fb1dfb1f22e8b18445468060c0864d36462114e29d

Contents?: true

Size: 759 Bytes

Versions: 6

Compression:

Stored size: 759 Bytes

Contents

require 'kafo/kafo_configure'
require 'kafo/data_type_parser'

module KafoModuleLint
  class TypeLoader
    attr_reader :modulepath

    def initialize(modulepath)
      @modulepath = modulepath

      # Workaround as DataTypeParser assumes KafoConfigure is in use
      Kafo::KafoConfigure.logger ||= Logger.new(STDERR)
    end

    def with_types(&block)
      parsers = Dir[type_pattern].map { |manifest| Kafo::DataTypeParser.new(File.read(manifest)) }
      parsers.each(&:register)
      yield
    ensure
      parsers.each do |parser|
        parser.types.keys.each { |type| Kafo::DataType.unregister_type(type) }
      end if parsers
    end

    private

    def type_pattern
      File.join(modulepath, '*', 'types', '**' , '*.pp')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kafo_module_lint-1.3.0 lib/kafo_module_lint/type_loader.rb
kafo_module_lint-1.1.0 lib/kafo_module_lint/type_loader.rb
kafo_module_lint-1.0.3 lib/kafo_module_lint/type_loader.rb
kafo_module_lint-1.0.2 lib/kafo_module_lint/type_loader.rb
kafo_module_lint-1.0.1 lib/kafo_module_lint/type_loader.rb
kafo_module_lint-1.0.0 lib/kafo_module_lint/type_loader.rb