Sha256: 0c2e9f20bc3d58481d2295582451e42b49901c0548f559d639bfa4f8840a2ad4

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true
module Decidim
  # Attachment can be any type of document or images related to a partcipatory
  # process.
  class ParticipatoryProcessAttachment < ApplicationRecord
    belongs_to :participatory_process, foreign_key: "decidim_participatory_process_id", class_name: Decidim::ParticipatoryProcess, inverse_of: :attachments

    validates :file, :participatory_process, :content_type, presence: true
    validates :file, file_size: { less_than_or_equal_to: 10.megabytes }
    mount_uploader :file, Decidim::AttachmentUploader

    # Whether this attachment is a photo or not.
    #
    # Returns Boolean.
    def photo?
      @photo ||= content_type.start_with? "image"
    end

    # Whether this attachment is a document or not.
    #
    # Returns Boolean.
    def document?
      !photo?
    end

    # Which kind of file this is.
    #
    # Returns String.
    def file_type
      file.file.extension
    end

    # The URL to download the file.
    #
    # Returns String.
    def url
      file.url
    end

    # The URL to download the thumbnail of the file. Only works with images.
    #
    # Returns String.
    def thumbnail_url
      return unless photo?
      file.thumbnail.url
    end

    # The URL to download the a big version of the file. Only works with images.
    #
    # Returns String.
    def big_url
      return unless photo?
      file.big.url
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-core-0.0.2 app/models/decidim/participatory_process_attachment.rb
decidim-core-0.0.1 app/models/decidim/participatory_process_attachment.rb