Class: WinewooCore::Services::Finders::Producers::AllProducersFinder

Inherits:
ProducersFinder
  • Object
show all
Defined in:
lib/winewoo_core/services/finders/producers/all_producers_finder.rb

Instance Method Summary collapse

Methods inherited from ProducersFinder

#initialize

Constructor Details

This class inherits a constructor from WinewooCore::Services::Finders::Producers::ProducersFinder

Instance Method Details

#findObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/winewoo_core/services/finders/producers/all_producers_finder.rb', line 4

def find
  query = WinewooCore::Repositories::Mongo::Queries::ProducerQuery.new(User.unscoped)
  query = query.from_interpro(@interpro.id) if @interpro
  query = @filters.scope_recents ? query.order_by(updated_at: :desc) : query.order_by(created_at: :asc)

  if @max_number
    (0..query.count-1).sort_by{rand}.slice(0, @max_number).collect! do |i|
      query.skip(i).first
    end
  else
    query.page(@page || 1)
      .per(@per_page || Kaminari::config.default_per_page)
  end
end