Class: MIME::Type::Columnar

Inherits:
MIME::Type show all
Defined in:
lib/mime/type/columnar.rb

Overview

A version of MIME::Type that works hand-in-hand with a MIME::Types::Columnar container to load data by columns.

When a field is has not yet been loaded, that data will be loaded for all types in the container before forwarding the message to MIME::Type.

More information can be found in MIME::Types::Columnar.

MIME::Type::Columnar is not intended to be created except by MIME::Types::Columnar containers.

Constant Summary

Constants inherited from MIME::Type

VERSION

Instance Attribute Summary

Attributes inherited from MIME::Type

#content_type, #docs, #encoding, #i18n_key, #media_type, #obsolete, #provisional, #raw_media_type, #raw_sub_type, #registered, #signature, #simplified, #sub_type, #use_instead, #xrefs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MIME::Type

#<=>, #__extension_priority_compare, #__sort_priority, #add_extensions, #ascii?, #binary?, #complete?, #default_encoding, #eql?, #extensions, #extensions=, #friendly, #hash, i18n_key, #init_with, #inspect, #like?, match, #preferred_extension, #preferred_extension=, #priority_compare, #provisional?, simplified, #to_h, #to_json, #to_s, #to_str, #xref_urls

Constructor Details

#initialize(container, content_type, extensions) ⇒ Columnar

:nodoc:



16
17
18
19
20
21
22
# File 'lib/mime/type/columnar.rb', line 16

def initialize(container, content_type, extensions) # :nodoc:
  @container = container
  @__priority_penalty = nil
  self.content_type = content_type
  @extensions = Set[*Array(extensions).flatten.compact].freeze
  clear_sort_priority
end

Class Method Details

.column(*methods, file: nil) ⇒ Object

:nodoc:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mime/type/columnar.rb', line 24

def self.column(*methods, file: nil) # :nodoc:
  file ||= methods.first

  file_method = :"load_#{file}"
  methods.each do |m|
    define_method m do |*args|
      @container.send(file_method)
      super(*args)
    end
  end
end

Instance Method Details

#encode_with(coder) ⇒ Object

:nodoc:



45
46
47
48
49
50
51
52
53
54
# File 'lib/mime/type/columnar.rb', line 45

def encode_with(coder) # :nodoc:
  @container.send(:load_friendly)
  @container.send(:load_encoding)
  @container.send(:load_docs)
  @container.send(:load_flags)
  @container.send(:load_use_instead)
  @container.send(:load_xrefs)
  @container.send(:load_preferred_extension)
  super
end

#update_sort_priorityObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/mime/type/columnar.rb', line 56

def update_sort_priority
  if @container.__fully_loaded?
    super
  else
    obsolete = (@__sort_priority & (1 << 7)) != 0
    registered = (@__sort_priority & (1 << 5)) == 0

    @__priority_penalty = (obsolete ? 3 : 0) + (registered ? 0 : 2)
  end
end