Class: Decidim::Attachment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Attachment
- Includes:
- HasUploadValidations, TranslatableResource
- Defined in:
- app/models/decidim/attachment.rb
Overview
Attachment can be any type of document or images related to a partcipatory process.
Instance Method Summary collapse
-
#big_url ⇒ Object
The URL to download the a big version of the file.
-
#context ⇒ Object
The context of the attachments defines which file upload settings constraints should be used when the file is uploaded.
-
#document? ⇒ Boolean
Whether this attachment is a document or not.
-
#file_type ⇒ Object
Which kind of file this is.
-
#organization ⇒ Object
Returns the organization related to this attachment in case the attached_to model belongs to an organization.
-
#photo? ⇒ Boolean
Whether this attachment is a photo or not.
-
#thumbnail_url ⇒ Object
The URL to download the thumbnail of the file.
Methods included from HasUploadValidations
#maximum_avatar_size, #maximum_upload_size
Instance Method Details
#big_url ⇒ Object
The URL to download the a big version of the file. Only works with images.
Returns String.
82 83 84 85 86 |
# File 'app/models/decidim/attachment.rb', line 82 def big_url return unless photo? file.big.url end |
#context ⇒ Object
The context of the attachments defines which file upload settings constraints should be used when the file is uploaded. The different contexts can limit for instance which file types the user is allowed to upload.
Returns Symbol.
38 39 40 41 42 |
# File 'app/models/decidim/attachment.rb', line 38 def context return attached_to. if attached_to.respond_to?(:attachment_context) :participant end |
#document? ⇒ Boolean
Whether this attachment is a document or not.
Returns Boolean.
54 55 56 |
# File 'app/models/decidim/attachment.rb', line 54 def document? !photo? end |
#file_type ⇒ Object
Which kind of file this is.
Returns String.
61 62 63 |
# File 'app/models/decidim/attachment.rb', line 61 def file_type file.url&.split(".")&.last&.downcase end |
#organization ⇒ Object
Returns the organization related to this attachment in case the attached_to model belongs to an organization. Otherwise will return nil.
Returns Decidim::Organization or nil.
24 25 26 27 28 29 30 |
# File 'app/models/decidim/attachment.rb', line 24 def organization return unless attached_to return attached_to if attached_to.is_a?(Decidim::Organization) return unless attached_to.respond_to?(:organization) attached_to.organization end |
#photo? ⇒ Boolean
Whether this attachment is a photo or not.
Returns Boolean.
47 48 49 |
# File 'app/models/decidim/attachment.rb', line 47 def photo? @photo ||= content_type.start_with? "image" end |
#thumbnail_url ⇒ Object
The URL to download the thumbnail of the file. Only works with images.
Returns String.
73 74 75 76 77 |
# File 'app/models/decidim/attachment.rb', line 73 def thumbnail_url return unless photo? file.thumbnail.url end |