assembler / attachinary

Attachments handler for Rails that uses Cloudinary for storage.
MIT License
295 stars 129 forks source link

raw files and resource type management #132

Open jerome opened 8 years ago

jerome commented 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 ?

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 ?

lionel218 commented 7 years ago

how to upload .xls and .doc files?