Sha256: 95e5cf0d5ab10f80d71c2e7e758d03f58f61b9b867821d8abeb956939ec9613b

Contents?: true

Size: 1.42 KB

Versions: 16

Compression:

Stored size: 1.42 KB

Contents

module Spree
  class Image < Asset
    include Configuration::ActiveStorage
    include Rails.application.routes.url_helpers
    include ::Spree::ImageMethods

    # In Rails 5.x class constants are being undefined/redefined during the code reloading process
    # in a rails development environment, after which the actual ruby objects stored in those class constants
    # are no longer equal (subclass == self) what causes error ActiveRecord::SubclassNotFound
    # Invalid single-table inheritance type: Spree::Image is not a subclass of Spree::Image.
    # The line below prevents the error.
    self.inheritance_column = nil

    def styles
      self.class.styles.map do |_, size|
        width, height = size.chop.split('x').map(&:to_i)

        {
          url: generate_url(size: size),
          size: size,
          width: width,
          height: height
        }
      end
    end

    def style(name)
      size = self.class.styles[name]
      return unless size

      width, height = size.chop.split('x').map(&:to_i)

      {
        url: generate_url(size: size),
        size: size,
        width: width,
        height: height
      }
    end

    def style_dimensions(name)
      size = self.class.styles[name]
      width, height = size.chop.split('x').map(&:to_i)

      {
        width: width,
        height: height
      }
    end

    def plp_url
      generate_url(size: self.class.styles[:plp_and_carousel])
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spree_core-4.6.6 app/models/spree/image.rb
spree_core-4.5.5 app/models/spree/image.rb
spree_core-4.5.4 app/models/spree/image.rb
spree_core-4.6.5 app/models/spree/image.rb
spree_core-4.7.2 app/models/spree/image.rb
spree_core-4.7.1 app/models/spree/image.rb
spree_core-4.6.4 app/models/spree/image.rb
spree_core-4.7.0 app/models/spree/image.rb
spree_core-4.6.3 app/models/spree/image.rb
spree_core-4.6.2 app/models/spree/image.rb
spree_core-4.6.1 app/models/spree/image.rb
spree_core-4.6.0 app/models/spree/image.rb
spree_core-4.5.3 app/models/spree/image.rb
spree_core-4.5.2 app/models/spree/image.rb
spree_core-4.5.1 app/models/spree/image.rb
spree_core-4.5.0 app/models/spree/image.rb