Sha256: 33e6bb54264c5837663d6e53b5d1e16f1977ce293757aa3f09d8787c6f1b9cc0

Contents?: true

Size: 1.57 KB

Versions: 55

Compression:

Stored size: 1.57 KB

Contents

require 'mime/type'

# 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.
class MIME::Type::Columnar < MIME::Type
  def initialize(container, content_type, extensions) # :nodoc:
    @container = container
    self.content_type = content_type
    self.extensions = extensions
  end

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

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

  column :friendly
  column :encoding, :encoding=
  column :docs, :docs=
  column :preferred_extension, :preferred_extension=
  column :obsolete, :obsolete=, :obsolete?, :registered, :registered=,
    :registered?, :signature, :signature=, :signature?, file: 'flags'
  column :xrefs, :xrefs=, :xref_urls
  column :use_instead, :use_instead=

  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

  class << self
    undef column
  end
end

Version data entries

55 entries across 51 versions & 9 rubygems

Version Path
kinetic_sdk-5.0.18 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.17 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.16 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.15 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.14 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.13 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.12 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.11 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.10 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.9 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.8 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.7 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.6 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.5 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.4 gems/mime-types-3.1/lib/mime/type/columnar.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.3 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.2 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.2.beta.4 gems/mime-types-3.1/lib/mime/type/columnar.rb
kinetic_sdk-5.0.2.beta.3 gems/mime-types-3.1/lib/mime/type/columnar.rb