module Shrine::Plugins::TypePredicates::FileMethods

Public Instance Methods

audio?() click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 33
def audio?
  general_type?("audio")
end
image?() click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 25
def image?
  general_type?("image")
end
text?() click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 37
def text?
  general_type?("text")
end
type?(type) click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 41
def type?(type)
  matching_mime_type = shrine_class.type_lookup(type)

  fail Error, "type #{type.inspect} is not recognized by the MIME library" unless matching_mime_type

  mime_type! == matching_mime_type
end
video?() click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 29
def video?
  general_type?("video")
end

Private Instance Methods

general_type?(type) click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 51
def general_type?(type)
  mime_type!.start_with?(type)
end
mime_type!() click to toggle source
# File lib/shrine/plugins/type_predicates.rb, line 55
def mime_type!
  mime_type or fail Error, "mime_type metadata value is missing"
end