Class: Workarea::FeaturedCategorization

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/queries/workarea/featured_categorization.rb

Instance Method Summary collapse

Constructor Details

#initialize(*product_ids) ⇒ FeaturedCategorization

Returns a new instance of FeaturedCategorization.



6
7
8
# File 'app/queries/workarea/featured_categorization.rb', line 6

def initialize(*product_ids)
  @product_ids = product_ids
end

Instance Method Details

#allObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/queries/workarea/featured_categorization.rb', line 10

def all
  @all ||= begin
    result = live

    categories_affected_by_current_release.each do |category|
      if product_featured_in_category?(category)
        result += [category] unless result.include?(category)
      else
        result -= [category]
      end
    end

    result
  end
end

#categories_affected_by_current_releaseObject



30
31
32
33
34
35
36
# File 'app/queries/workarea/featured_categorization.rb', line 30

def categories_affected_by_current_release
  return [] if Release.current.blank?

  Catalog::Category.in(
    id: category_changesets_affecting_current_release.map(&:releasable_id)
  )
end

#category_changesets_affecting_current_releaseObject



38
39
40
41
42
43
44
45
# File 'app/queries/workarea/featured_categorization.rb', line 38

def category_changesets_affecting_current_release
  return [] if Release.current.blank?

  FeaturedProducts
    .changesets(*@product_ids)
    .where(releasable_type: Catalog::Category.name)
    .in(release_id: Release.current.preview.releases.map(&:id))
end

#liveObject



26
27
28
# File 'app/queries/workarea/featured_categorization.rb', line 26

def live
  @live ||= Catalog::Category.by_product(@product_ids).to_a
end