Sha256: 87e5e6122bb0d16f53f0d0b64d4726e84b3961633a7642d25a9ddd0aab5ce677
Contents?: true
Size: 1.29 KB
Versions: 13
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 fail "Error: Unknown file format #{format.inspect}" end end end end end end require_relative 'all'
Version data entries
13 entries across 13 versions & 1 rubygems