Open jerome opened 8 years ago
Hello
Since image resource type describes both images and pdf while everything else is raw with format set to nil, how about to extend the file mixin to retrieve resource types with enhanced accuracy ?
format
nil
Something like:
scope :image, -> { where(resource_type: "image").where.not(format: "pdf") } def image? resource_type == "image" && format != "pdf" end scope :pdf, -> { where(format: "pdf") } def pdf? format == "pdf" end scope :video, -> { where(resource_type: "video") } def video? resource_type == "video" end scope :document, -> { where("resource_type = ? AND public_id ~* ?", "raw", "\.(txt|docx?|rtf|odt)$" ) } def document? resource_type == "raw" && !!( public_id =~ /\.(txt|docx?|rtf|odt)$/ ) end scope :presentation, -> { where("resource_type = ? AND public_id ~* ?", "raw", "\.(pptx?|odp)$" ) } def presentation? resource_type == "raw" && !!( public_id =~ /\.(pptx?|odp)$/ ) end scope :spreadsheet, -> { where("resource_type = ? AND public_id ~* ?", "raw", "\.(csv|xslx?|ods)$" ) } def spreadsheet? resource_type == "raw" && !!( public_id =~ /\.(csv|xslx?|ods)$/ ) end
etc.
That also means new table indices and methods for each ORM (I only know active record).
Else, how do you daily handle that matter ?
how to upload .xls and .doc files?
Hello
Since image resource type describes both images and pdf while everything else is raw with
format
set tonil
, how about to extend the file mixin to retrieve resource types with enhanced accuracy ?Something like:
etc.
That also means new table indices and methods for each ORM (I only know active record).
Else, how do you daily handle that matter ?