Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raw files and resource type management #132

Open
jerome opened this issue Jul 10, 2016 · 1 comment
Open

raw files and resource type management #132

jerome opened this issue Jul 10, 2016 · 1 comment

Comments

@jerome
Copy link
Contributor

jerome commented Jul 10, 2016

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
Copy link

how to upload .xls and .doc files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants