Sha256: 949da54afd15f804d5efd949d6aab58d1b3b972d4e3e32860a560dd952294806

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

module Workarea
  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

14 entries across 14 versions & 1 rubygems

Version Path
workarea-core-3.5.12 app/queries/workarea/product_releases.rb
workarea-core-3.5.11 app/queries/workarea/product_releases.rb
workarea-core-3.5.10 app/queries/workarea/product_releases.rb
workarea-core-3.5.9 app/queries/workarea/product_releases.rb
workarea-core-3.5.8 app/queries/workarea/product_releases.rb
workarea-core-3.5.7 app/queries/workarea/product_releases.rb
workarea-core-3.5.6 app/queries/workarea/product_releases.rb
workarea-core-3.5.5 app/queries/workarea/product_releases.rb
workarea-core-3.5.4 app/queries/workarea/product_releases.rb
workarea-core-3.5.3 app/queries/workarea/product_releases.rb
workarea-core-3.5.2 app/queries/workarea/product_releases.rb
workarea-core-3.5.1 app/queries/workarea/product_releases.rb
workarea-core-3.5.0 app/queries/workarea/product_releases.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/product_releases.rb