Sha256: 9a5aa9b5bedfe919977def9f821f6ca7531511df338698a7000d8735e5877294

Contents?: true

Size: 1.29 KB

Versions: 34

Compression:

Stored size: 1.29 KB

Contents

require 'ndr_support/safe_file'

module NdrImport
  module File
    # This mixin adds table enumeration functionality to importers.
    module Registry
      class <<self
        attr_accessor :handlers

        def register(klass, *formats)
          @handlers ||= {}

          formats.each do |format|
            @handlers[format] = klass
          end
        end

        def unregister(*formats)
          formats.each do |format|
            @handlers.delete(format)
          end
        end

        def files(filename, options = {}, &block)
          return enum_for(:files, filename, options) unless block

          klass_factory(filename, nil, options).files(&block)
        end

        def tables(filename, format = nil, options = {}, &block)
          return enum_for(:tables, filename, format, options) unless block

          klass_factory(filename, format, options).tables(&block)
        end

        private

        def klass_factory(filename, format, options)
          format ||= SafeFile.extname(filename).delete('.').downcase
          klass = Registry.handlers[format]
          if klass
            klass.new(filename, format, options)
          else
            UnregisteredFiletype.new(filename, format, options)
          end
        end
      end
    end
  end
end

require_relative 'all'

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ndr_import-11.2.1 lib/ndr_import/file/registry.rb
ndr_import-11.2.0 lib/ndr_import/file/registry.rb
ndr_import-11.1.0 lib/ndr_import/file/registry.rb
ndr_import-11.0.2 lib/ndr_import/file/registry.rb
ndr_import-11.0.1 lib/ndr_import/file/registry.rb
ndr_import-11.0.0 lib/ndr_import/file/registry.rb
ndr_import-10.3.0 lib/ndr_import/file/registry.rb
ndr_import-10.2.0 lib/ndr_import/file/registry.rb
ndr_import-10.1.3 lib/ndr_import/file/registry.rb
ndr_import-10.1.2 lib/ndr_import/file/registry.rb
ndr_import-10.1.1 lib/ndr_import/file/registry.rb
ndr_import-10.1 lib/ndr_import/file/registry.rb
ndr_import-10.0 lib/ndr_import/file/registry.rb
ndr_import-9.1.0 lib/ndr_import/file/registry.rb
ndr_import-9.0.3 lib/ndr_import/file/registry.rb
ndr_import-9.0.2 lib/ndr_import/file/registry.rb
ndr_import-9.0.1 lib/ndr_import/file/registry.rb
ndr_import-9.0.0 lib/ndr_import/file/registry.rb
ndr_import-8.6.0 lib/ndr_import/file/registry.rb
ndr_import-8.5.2 lib/ndr_import/file/registry.rb