class MIME::Type

Constants

DISTORTED_METHOD_PREFIXES

Provide a few variations on the base :distorted_method for mixed workflows where it isn't feasible to overload a single method name and call :super. Jekyll, for example, renders its output markup upfront, collects all of the StaticFiles (or StaticStatic-includers, in our case), then calls their :write methods all at once after the rest of the site is built, and this precludes us from easily sharing method names between layers.

SUB_TYPE_SEPARATORS

Public Instance Methods

distorted_buffer_method() click to toggle source

Returns a Symbol name of the method that should return a String buffer containing the file in this Type.

# File lib/distorted/checking_you_out.rb, line 59
def distorted_buffer_method; "#{DISTORTED_METHOD_PREFIXES[:buffer]}_#{distorted_method_suffix}".to_sym; end
distorted_file_method() click to toggle source

Returns a Symbol name of the method that should write a file of this Type to a given path on a filesystem.

# File lib/distorted/checking_you_out.rb, line 62
def distorted_file_method; "#{DISTORTED_METHOD_PREFIXES[:file]}_#{distorted_method_suffix}".to_sym; end
distorted_template_method() click to toggle source

Returns a Symbol name of the method that should returns a context-appropriate Object for displaying the file as this Type. Might be e.g. a String buffer containing Rendered Liquid in Jekylland, or a Type-appropriate frame in some GUI toolkit in DD-Booth.

# File lib/distorted/checking_you_out.rb, line 68
def distorted_template_method; "#{DISTORTED_METHOD_PREFIXES[:template]}_#{distorted_method_suffix}".to_sym; end
settings_paths() click to toggle source

Returns an Array[Array] of human-readable keys we can use for our YAML config, e.g. :media_type 'image' & :sub_type 'svg+xml' would be split to ['image', 'svg']. `nil` `:sub_type`s will just be compacted out. Every non-nil :media_type will also request a key path [media_type, '*'] to allow for similar-type defaults, e.g. every image type outputting a fallback.

# File lib/distorted/checking_you_out.rb, line 75
def settings_paths; [[self.media_type, '*'.freeze], [self.media_type, self.sub_type&.split('+'.freeze)&.first].compact]; end

Private Instance Methods

distorted_method_suffix() click to toggle source

Provide a consistent base method name for context-specific DistorteD operations.

# File lib/distorted/checking_you_out.rb, line 80
def distorted_method_suffix
  # Standardize MIME::Types' media_type+sub_type to DistorteD method mapping
  # by replacing all the combining characters with underscores (snake case)
  # to match Ruby conventions:
  # https://rubystyle.guide/#snake-case-symbols-methods-vars
  #
  # For the worst possible example, an intended outout Type of
  # "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  # (a.k.a. a MSWord `docx` file) would map to a DistorteD saver method
  # :to_application_vnd_openxmlformats_officedocument_wordprocessingml_document
  # which would most likely be defined by the :included method of a library-specific
  # module for handling OpenXML MS Office documents.
  "#{self.media_type}_#{self.sub_type.gsub(SUB_TYPE_SEPARATORS, '_'.freeze)}"
end