Class: Spree::Posts::Find

Inherits:
BaseFinder show all
Defined in:
app/finders/spree/posts/find.rb

Instance Attribute Summary

Attributes inherited from BaseFinder

#params

Instance Method Summary collapse

Constructor Details

#initialize(scope:, params:) ⇒ Find

Returns a new instance of Find.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/finders/spree/posts/find.rb', line 4

def initialize(scope:, params:)
  super(scope: scope, params: params)
  @scope = scope
  @query = params[:q].presence&.strip
  @ids = String(params.dig(:filter, :ids)).split(',')
  @slugs = String(params.dig(:filter, :slugs)).split(',')
  @category_ids = String(params.dig(:filter, :category_ids)).split(',')
  @author_ids = String(params.dig(:filter, :author_ids)).split(',')
  @tags = params.dig(:filter, :tags).to_s.split(',').compact_blank
  @sort_by = params[:sort_by]
  @published = params.dig(:filter, :published)
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/finders/spree/posts/find.rb', line 17

def execute
  posts = by_ids(scope)
  posts = by_slugs(posts)
  posts = by_query(posts)
  posts = by_category_ids(posts)
  posts = by_author_ids(posts)
  posts = by_tags(posts)
  posts = by_published(posts)
  posts = ordered(posts)

  posts.distinct
end