Class: Workarea::ProductReleases

Inherits:
Object
  • Object
show all
Defined in:
app/queries/workarea/product_releases.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product) ⇒ ProductReleases

Returns a new instance of ProductReleases.



5
6
7
# File 'app/queries/workarea/product_releases.rb', line 5

def initialize(product)
  @product = product
end

Instance Attribute Details

#productObject (readonly)

Returns the value of attribute product.



3
4
5
# File 'app/queries/workarea/product_releases.rb', line 3

def product
  @product
end

Instance Method Details

#changesetsMongoid::Criteria

All Releasables that could affect the product’s Elasticsearch document should add their changesets to this method.

Examples:

Add to the changesets affecting a product in a decorator

def changesets
  super.merge(SomeReleasable.for_product(product.id).changesets_with_children)
end

Returns:



27
28
29
30
31
32
# File 'app/queries/workarea/product_releases.rb', line 27

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

#pricing_skusObject



34
35
36
# File 'app/queries/workarea/product_releases.rb', line 34

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

#releasesObject



9
10
11
12
13
14
15
# File 'app/queries/workarea/product_releases.rb', line 9

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