Sha256: 12bd69fbe5be418b402f5e2e01337b0621bbf8d6856c4572095b6b994267c485

Contents?: true

Size: 1.47 KB

Versions: 11

Compression:

Stored size: 1.47 KB

Contents

module Para
  module Library
    class File < Para::ApplicationRecord
      if defined?(ActiveStorage)
        has_one_attached :attachment

        # Return attachment.path or attachment.url depending on the storage
        # backend, allowing 'openuri' and 'roo' libraries to load easily the
        # file at the right path, on filesystem or othe storage systems, like S3.
        #
        def attachment_path
          return unless attachment.attached?

          attachment.service_url
        end

        alias_method :attachment_url, :attachment_path

        def attachment_ext
          ::File.extname(attachment.filename.to_s) if attachment.attached?
        end
      else
        has_attached_file :attachment

        validates :attachment, presence: true
        do_not_validate_attachment_file_type :attachment

        # Return attachment.path or attachment.url depending on the storage
        # backend, allowing 'openuri' and 'roo' libraries to load easily the
        # file at the right path, on filesystem or othe storage systems, like S3.
        #
        def attachment_path
          return unless attachment?

          case attachment.options[:storage]
          when :filesystem then attachment.path
          else attachment.url
          end
        end

        def attachment_url
          attachment.url if attachment?
        end

        def attachment_ext
          ::File.extname(attachment_file_name) if attachment.attached?
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
para-0.9.4 app/models/para/library/file.rb
para-0.9.3.3 app/models/para/library/file.rb
para-0.9.3.2 app/models/para/library/file.rb
para-0.9.3.1 app/models/para/library/file.rb
para-0.9.2 app/models/para/library/file.rb
para-0.9.0 app/models/para/library/file.rb
para-0.8.15 app/models/para/library/file.rb
para-0.8.14 app/models/para/library/file.rb
para-0.8.13 app/models/para/library/file.rb
para-0.8.12 app/models/para/library/file.rb
para-0.8.11 app/models/para/library/file.rb