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.10.1 app/finders/spree/cms_pages/find.rb
spree_core-4.10.0 app/finders/spree/cms_pages/find.rb
spree_core-4.9.0 app/finders/spree/cms_pages/find.rb
spree_core-4.8.3 app/finders/spree/cms_pages/find.rb
spree_core-4.8.2 app/finders/spree/cms_pages/find.rb
spree_core-4.7.3 app/finders/spree/cms_pages/find.rb
spree_core-4.6.6 app/finders/spree/cms_pages/find.rb
spree_core-4.5.5 app/finders/spree/cms_pages/find.rb
spree_core-4.3.3 app/finders/spree/cms_pages/find.rb
spree_core-4.4.1 app/finders/spree/cms_pages/find.rb
spree_core-4.5.4 app/finders/spree/cms_pages/find.rb
spree_core-4.6.5 app/finders/spree/cms_pages/find.rb
spree_core-4.7.2 app/finders/spree/cms_pages/find.rb
spree_core-4.7.1 app/finders/spree/cms_pages/find.rb
spree_core-4.6.4 app/finders/spree/cms_pages/find.rb
spree_core-4.7.0 app/finders/spree/cms_pages/find.rb
spree_core-4.6.3 app/finders/spree/cms_pages/find.rb
spree_core-4.6.2 app/finders/spree/cms_pages/find.rb
spree_core-4.6.1 app/finders/spree/cms_pages/find.rb
spree_core-4.6.0 app/finders/spree/cms_pages/find.rb