Sha256: 0b009b0d797857df7126daae3518565161d75c091d90cd126a7ef1505b0a67d7

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

module Workarea
  #
  # TODO remove in v3.6
  #
  # This is no longer used, this logic was moved into the search models to allow
  # it to be used for any model (not just products).
  #
  class ProductReleases
    attr_reader :product

    def initialize(product)
      @product = product
    end

    def releases
      changesets
        .uniq(&:release)
        .reject { |cs| cs.release.blank? }
        .flat_map { |cs| [cs.release] + cs.release.scheduled_after }
        .uniq
    end

    # All {Releasable}s that could affect the product's Elasticsearch document
    # should add their changesets to this method.
    #
    # @example Add to the changesets affecting a product in a decorator
    #   def changesets
    #     super.merge(SomeReleasable.for_product(product.id).changesets_with_children)
    #   end
    #
    # @return [Mongoid::Criteria]
    #
    def changesets
      criteria = product.changesets_with_children
      pricing_skus.each { |ps| criteria.merge!(ps.changesets_with_children) }
      criteria.merge!(FeaturedProducts.changesets(product.id))
      criteria.includes(:release)
    end

    def pricing_skus
      Pricing::Sku.in(id: product.skus).to_a
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
workarea-core-3.5.21 app/queries/workarea/product_releases.rb
workarea-core-3.5.20 app/queries/workarea/product_releases.rb
workarea-core-3.5.19 app/queries/workarea/product_releases.rb
workarea-core-3.5.18 app/queries/workarea/product_releases.rb
workarea-core-3.5.17 app/queries/workarea/product_releases.rb
workarea-core-3.5.16 app/queries/workarea/product_releases.rb
workarea-core-3.5.15 app/queries/workarea/product_releases.rb
workarea-core-3.5.14 app/queries/workarea/product_releases.rb
workarea-core-3.5.13 app/queries/workarea/product_releases.rb