Sha256: f4b270308081910d38912ac56b4cce8f7d1aedb168a4941d4a626751fee58569

Contents?: true

Size: 957 Bytes

Versions: 1

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

class RefMaterial < SatelliteAsset
  sunrise_uploader RefMaterialUploader

  validates_filesize_of :data, maximum: 50.megabytes.to_i

  def thumb_url; end

  class << self
    def destroy(params)
      {
        files: [
          remoteupload_klass.destroy(params).try(:attributes)
        ]
      }
    rescue JsonApiClient::Errors::ApiError
      { files: [] }
    end

    def remoteupload_klass
      TranslationCms::Api::Customers::ReferenceMaterial
    end
  end

  def remote_token
    data.try(:file).try(:public_token)
  end

  def as_json(options = nil)
    options = {
      root: false,
      only: [:id, :guid, :assetable_id, :assetable_type, :user_id, :public_token],
      methods: [:filename, :url, :thumb_url, :size, :content_type, :remote_token]
    }.merge(options || {})
    super(options)
  end

  def to_fileupload
    as_json
  end

  def remoteupload_klass
    self.class.remoteupload_klass
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/models/media/ref_material.rb