Class: FindByTagsStrategy

Inherits:
QueryStrategy show all
Defined in:
lib/needle_in_a_haystack/strategies/find_by_tags_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, tags) ⇒ FindByTagsStrategy

Returns a new instance of FindByTagsStrategy.



2
3
4
5
6
# File 'lib/needle_in_a_haystack/strategies/find_by_tags_strategy.rb', line 2

def initialize(model, tags)
  super()
  @model = model
  @tags = tags
end

Instance Method Details

#executeObject



8
9
10
# File 'lib/needle_in_a_haystack/strategies/find_by_tags_strategy.rb', line 8

def execute
  @model.joins(:haystack_tags).where(haystack_tags: { id: @tags.map(&:id) })
end