Sha256: 0d4b7f17c8217312b72359f407e0714613547c260b788e5e46701fb4bfafb55e

Contents?: true

Size: 1.59 KB

Versions: 18

Compression:

Stored size: 1.59 KB

Contents

module MessageTrain
  # Attachment model
  class Attachment < ActiveRecord::Base
    belongs_to :message, foreign_key: :message_train_message_id, touch: true
    has_attached_file(
      :attachment,
      styles: lambda do |attachment|
        if attachment.instance.image?
          {
            thumb: '235x',
            large: '800x'
          }
        else
          {}
        end
      end,
      path: ':rails_root/public/system/:rails_env/:class/:attachment/'\
        ':id_partition/:style_prefix:filename',
      url: '/system/:rails_env/:class/:attachment/'\
        ':id_partition/:style_prefix:filename',
      convert_options: {
        large: '-quality 75 -interlace Plane -strip',
        thumb: '-quality 75 -strip'
      }
    )
    validates_attachment_presence :attachment
    validates_attachment_content_type(
      :attachment,
      content_type: [
        'application/pdf',
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/msword',
        'application/'\
          'vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/rtf',
        'text/plain',
        %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$}
      ]
    )
    def image?
      # rubocop:disable Style/LineLength
      !(attachment_content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$}).nil?
      # rubocop:enable Style/LineLength
    end

    Paperclip.interpolates :style_prefix do |attachment, style|
      attachment.instance.image? ? "#{style}/" : ''
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
message_train-0.6.17 app/models/message_train/attachment.rb
message_train-0.6.16 app/models/message_train/attachment.rb
message_train-0.6.15 app/models/message_train/attachment.rb
message_train-0.6.14 app/models/message_train/attachment.rb
message_train-0.6.13 app/models/message_train/attachment.rb
message_train-0.6.12 app/models/message_train/attachment.rb
message_train-0.6.11 app/models/message_train/attachment.rb
message_train-0.6.10 app/models/message_train/attachment.rb
message_train-0.6.9 app/models/message_train/attachment.rb
message_train-0.6.8 app/models/message_train/attachment.rb
message_train-0.6.7 app/models/message_train/attachment.rb
message_train-0.6.6 app/models/message_train/attachment.rb
message_train-0.6.5 app/models/message_train/attachment.rb
message_train-0.6.4 app/models/message_train/attachment.rb
message_train-0.6.3 app/models/message_train/attachment.rb
message_train-0.6.2 app/models/message_train/attachment.rb
message_train-0.6.1 app/models/message_train/attachment.rb
message_train-0.6.0 app/models/message_train/attachment.rb