Module: ROM::Files::Plugins::Schema::Mime

Defined in:
lib/rom/files/plugins/schema/mime.rb

Overview

A plugin for obtaining MIME-type of file using its name

Examples:

Generic mime_type field

schema do
  use :mime_type
end

Defined Under Namespace

Modules: DSL

Constant Summary collapse

PROC =
->(path) { MIME::Types.type_for(path.basename.to_s).first }
TYPE =
Types::MimeType.optional

Class Method Summary collapse

Class Method Details

.apply(schema, name: :mime_type, type: TYPE) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rom/files/plugins/schema/mime.rb', line 24

def self.apply(schema, name: :mime_type, type: TYPE)
  mime_type = type.meta(
    name: name,
    __proc__: PROC,
    source: schema.name
  )

  schema.attributes.concat(
    schema.class.attributes([mime_type], schema.attr_class)
  )
end