Paperclip.interpolates(:compatible_id) do |attachment, _style|
  attachment.instance.legacy_id || attachment.instance.id
end

':class/:attachment/:compatible_id/:style/:basename.:extension'.tap do |path|
  if Supermarket::Config.s3
    ::Paperclip::Attachment.default_options.update(
      storage: 's3',
      s3_credentials: Supermarket::Config.s3,
      url: ':s3_path_url',
      path: path,
      bucket: Supermarket::Config.s3['bucket']
    )
  else
    ::Paperclip::Attachment.default_options.update(
      storage: :filesystem,
      path: ':rails_root/public:url',
      url: "/system/#{path}"
    )
  end
end

Paperclip.interpolates(:compatible_id) do |attachment, _style|
  attachment.instance.legacy_id || attachment.instance.id
end

':class/:attachment/:compatible_id/:style/:basename.:extension'.tap do |path|
  if Supermarket::Config.s3
    ::Paperclip::Attachment.default_options.update(
      storage: 's3',
      s3_credentials: Supermarket::Config.s3,
      url: ':s3_path_url',
      path: path,
      bucket: Supermarket::Config.s3['bucket'],
      s3_protocol: ENV['PROTOCOL']
    )
  else
    ::Paperclip::Attachment.default_options.update(
      storage: :filesystem,
      path: ':rails_root/public:url',
      url: "/system/#{path}"
    )
  end
end

Use same protocol for S3 URLs as the application
Use same protocol for S3 URLs as the application

Berkshelf is not happy if the protocol for the application is not the
same as the S3 URLs so this configures Paperclip to use the same
protocol.
