Sha256: 024cee0963bebf37563f1dc4d71614c780452b8f18ca11a1a65ba96fa636d6c6

Contents?: true

Size: 825 Bytes

Versions: 33

Compression:

Stored size: 825 Bytes

Contents

module Spree
  module CmsPages
    class Find < ::Spree::BaseFinder
      ALLOWED_KINDS = %w[standard home feature].freeze

      def initialize(scope:, params:)
        @scope = scope
        @title = params.dig(:filter, :title)
        @kind  = params.dig(:filter, :type)
      end

      def execute
        pages = by_title(scope)
        pages = by_kind(pages)

        pages
      end

      private

      attr_reader :scope, :title, :kind

      def title_matcher
        Spree::CmsPage.arel_table[:title].matches("%#{title}%")
      end

      def by_title(pages)
        return pages if title.blank?

        pages.where(title_matcher)
      end

      def by_kind(pages)
        return pages if kind.blank?
        return pages if ALLOWED_KINDS.exclude?(kind)

        pages.send(kind)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
spree_core-4.5.3 app/finders/spree/cms_pages/find.rb
spree_core-4.5.2 app/finders/spree/cms_pages/find.rb
spree_core-4.5.1 app/finders/spree/cms_pages/find.rb
spree_core-4.5.0 app/finders/spree/cms_pages/find.rb
spree_core-4.3.2 app/finders/spree/cms_pages/find.rb
spree_core-4.4.0 app/finders/spree/cms_pages/find.rb
spree_core-4.4.0.rc2 app/finders/spree/cms_pages/find.rb
spree_core-4.3.1 app/finders/spree/cms_pages/find.rb
spree_core-4.4.0.rc1 app/finders/spree/cms_pages/find.rb
spree_core-4.3.0 app/finders/spree/cms_pages/find.rb
spree_core-4.3.0.rc3 app/finders/spree/cms_pages/find.rb
spree_core-4.3.0.rc2 app/finders/spree/cms_pages/find.rb
spree_core-4.3.0.rc1 app/finders/spree/cms_pages/find.rb