Sha256: 9560ed5194996842f0d5a35c7f8d50989b2c7b5e093a21171ee3c4343d03fe98

Contents?: true

Size: 683 Bytes

Versions: 27

Compression:

Stored size: 683 Bytes

Contents

module Spina
  class Image < ApplicationRecord
    belongs_to :media_folder, optional: true

    has_one_attached :file

    scope :sorted, -> { order('created_at DESC') }

    def name
      file.try(:filename).to_s
    end

    def variant(options)
      return "" unless file.attached?
      return file if file.content_type.include?('svg')
      return file unless file.variable?

      file.variant(options)
    end

    def content
      self
    end

    def thumbnail(size = '100x100', modifier = '^')
      variant(
        combine_options: {
          gravity: 'center',
          thumbnail: "#{size}#{modifier}",
          extent: size
        }
      )
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
spina-2.12.0 app/models/spina/image.rb
spina-2.11.0 app/models/spina/image.rb
spina-2.10.0 app/models/spina/image.rb
spina-2.9.1 app/models/spina/image.rb
spina-2.9.0 app/models/spina/image.rb
spina-2.8.1 app/models/spina/image.rb
spina-2.8.0 app/models/spina/image.rb
spina-2.7.0 app/models/spina/image.rb
spina-2.6.2 app/models/spina/image.rb
spina-2.6.1 app/models/spina/image.rb
spina-2.6.0 app/models/spina/image.rb
spina-2.5.0 app/models/spina/image.rb
spina-2.4.0 app/models/spina/image.rb
spina-2.3.5 app/models/spina/image.rb
spina-2.3.4 app/models/spina/image.rb
spina-2.3.3 app/models/spina/image.rb
spina-2.3.2 app/models/spina/image.rb
spina-2.3.1 app/models/spina/image.rb
spina-2.3.0 app/models/spina/image.rb
spina-2.2.0 app/models/spina/image.rb