Sha256: 6e925c710f5abaa09d00b5042f1e0f7090fbfd3cf091b7d317ffd0797fae13c7

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

# frozen_string_literal: true

require 'administrate/field/base'
require 'rails'

module Administrate
  module Field
    class Carrierwave < Administrate::Field::Base
      class Engine < ::Rails::Engine; end

      def image
        options.fetch(:image, nil)
      end

      def image_on_index?
        options.fetch(:image_on_index, false)
      end

      def multiple?
        options.fetch(:multiple, false)
      end

      def remove?
        options.fetch(:remove, false)
      end

      def remote_url?
        options.fetch(:remote_url, false)
      end

      def files
        Array[*data]
      end

      def file
        files.first
      end

      def model
        data.try(:model)
      end

      def show_preview?
        has_file = model.try(:persisted?) && file.present?
        has_file && (image ? file.version_exists?(image) : true)
      end

      def show_file?
        file.present?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
administrate-field-carrierwave-0.3.4 lib/administrate/field/carrierwave.rb