Sha256: 9d396a6bb4cec10af1640f64c5f7d5b4b5ccb007234e2f20c35cdd7c7e4e749e

Contents?: true

Size: 1.14 KB

Versions: 12

Compression:

Stored size: 1.14 KB

Contents

module Workarea
  module Search
    # This class exists to provide plugins and host applications a single
    # point of modification for changing the logic around indexing products
    # See workarea-browse_option or workarea-package_products for example.
    #
    class ProductEntries
      include Enumerable
      delegate :any?, :empty?, :each, :size, to: :entries

      def initialize(products)
        @products = Array.wrap(products)
      end

      def entries
        @entries ||= live_entries + release_entries
      end

      def live_entries
        @live_entries ||= @products.reduce([]) do |memo, product|
          memo + Array.wrap(index_entries_for(product.without_release))
        end
      end

      def release_entries
        @release_entries ||= @products.reduce([]) do |results, product|
          releases = ProductReleases.new(product).releases

          results + releases.reduce([]) do |memo, release|
            memo + Array.wrap(index_entries_for(product.in_release(release)))
          end
        end
      end

      def index_entries_for(product)
        Search::Storefront::Product.new(product)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
workarea-core-3.5.20 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.19 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.18 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.17 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.16 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.15 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.14 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.13 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.12 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.11 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.10 app/queries/workarea/search/product_entries.rb
workarea-core-3.5.9 app/queries/workarea/search/product_entries.rb