Sha256: 6bbe8d37d2454e73a5cc749235cb40de94d518f45589e086a1260dd6acddeddf

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module Workarea
  module Admin
    class FeaturedProductsSearchViewModel < SearchViewModel
      def results
        @results ||= PagedArray.from(
          browse_option_results,
          model.results.page,
          model.results.per_page,
          total
        )
      end

      # Yes, I know this is dumb. But there seems to be a bug with flat_map and
      # flatten that is driving me fucking crazy and i need to avoid it.
      #
      def browse_option_results
        results = []

        persisted_results.each do |model|
          if model.browses_by_option?
            model.browse_options.each do |option|
              results.push(
                FeaturedBrowseOptionProductViewModel.wrap(
                  model,
                  view_model_options_for(model).merge(
                    model.browse_option => option.optionize
                  )
                )
              )
            end
          else
            results.push(
              FeaturedBrowseOptionProductViewModel.wrap(
                model,
                view_model_options_for(model)
              )
            )
          end
        end

        results
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-browse_option-2.2.0 app/view_models/workarea/admin/featured_products_search_view_model.rb
workarea-browse_option-2.1.9 app/view_models/workarea/admin/featured_products_search_view_model.rb
workarea-browse_option-2.1.8 app/view_models/workarea/admin/featured_products_search_view_model.rb
workarea-browse_option-2.1.7 app/view_models/workarea/admin/featured_products_search_view_model.rb
workarea-browse_option-2.1.6 app/view_models/workarea/admin/featured_products_search_view_model.rb