# module MIME::Types::Columnar

MIME::Types::Columnar is used to extend a MIME::Types container to load data by columns instead of from JSON or YAML. Column loads of MIME types loaded through the columnar store are synchronized with a Mutex.

MIME::Types::Columnar is not intended to be used directly, but will be added to an instance of MIME::Types when it is loaded with MIME::Types::Loader#load_columnar.

### Private Instance Methods

arr(line) click to toggle source

    # File lib/mime/types/columnar.rb, line 137
    def arr(line)
      if line == '-'.freeze
        []
      else
        line.split('|'.freeze).flatten.compact.uniq
      end
    end

bool(line) click to toggle source

    # File lib/mime/types/columnar.rb, line 145
    def bool(line)
      line == '1'.freeze ? true : false
    end

dict(line) click to toggle source

    # File lib/mime/types/columnar.rb, line 125
    def dict(line)
      if line == '-'.freeze
        {}
      else
        line.split('|'.freeze).each_with_object({}) { |h, l|
          k, v = l.split('^'.freeze)
          v = [ nil ] if v.empty?
          h[k] = v
        }
      end
    end

each_file_line(name, lookup = true) { |type, line| ... } click to toggle source

    # File lib/mime/types/columnar.rb, line 41
    def each_file_line(name, lookup = true)
      LOAD_MUTEX.synchronize do
        next if @__attributes__.include?(name)

        File.open(File.join(@__root__, "mime.#{name}.column"), 'r:UTF-8') do |f|
          i = -1

          f.each_line do |line|
            line.chomp!

            if lookup
              type = @__mime_data__[i += 1] or next
              yield type, line
            else
              yield line
            end
          end
        end

        @__attributes__ << name
      end
    end

load_docs() click to toggle source

    # File lib/mime/types/columnar.rb, line 72
    def load_docs
      each_file_line('docs') do |type, line|
        type.docs = arr(line)
      end
    end

load_encoding() click to toggle source

    # File lib/mime/types/columnar.rb, line 64
    def load_encoding
      pool = {}
      each_file_line('encoding') do |type, line|
        line.freeze
        type.encoding = (pool[line] ||= line)
      end
    end

load_friendly() click to toggle source

    # File lib/mime/types/columnar.rb, line 112
    def load_friendly
      each_file_line('friendly') { |type, line|
        v = dict(line)
        type.friendly = v.empty? ? nil : v
      }
    end

load_obsolete() click to toggle source

    # File lib/mime/types/columnar.rb, line 78
    def load_obsolete
      each_file_line('obsolete') do |type, line|
        type.obsolete = bool(line)
      end
    end

load_references() click to toggle source

    # File lib/mime/types/columnar.rb, line 84
    def load_references
      each_file_line('references') do |type, line|
        type.instance_variable_set(:@references, arr(line))
      end
    end

load_registered() click to toggle source

    # File lib/mime/types/columnar.rb, line 90
    def load_registered
      each_file_line('registered') do |type, line|
        type.registered = bool(line)
      end
    end

load_signature() click to toggle source

    # File lib/mime/types/columnar.rb, line 96
    def load_signature
      each_file_line('signature') do |type, line|
        type.signature = bool(line)
      end
    end

load_system() click to toggle source

    # File lib/mime/types/columnar.rb, line 102
    def load_system
      each_file_line('system') do |type, line|
        type.system = (line unless line == '-'.freeze)
      end
    end

load_use_instead() click to toggle source

    # File lib/mime/types/columnar.rb, line 119
    def load_use_instead
      each_file_line('use_instead') do |type, line|
        type.use_instad = (line unless line == '-'.freeze)
      end
    end

load_xrefs() click to toggle source

    # File lib/mime/types/columnar.rb, line 108
    def load_xrefs
      each_file_line('xrefs') { |type, line| type.xrefs = dict(line) }
    end