rosa-build/app/models/search.rb

28 lines
543 B
Ruby
Raw Normal View History

2014-11-17 21:17:03 +00:00
class Search < Struct.new(:query, :ability, :paginate_params)
include ActiveModel::Conversion
extend ActiveModel::Naming
2012-11-21 15:04:41 +00:00
2014-11-17 21:17:03 +00:00
TYPES = %w(projects users groups platforms)
TYPES.each do |type|
define_method type do
find_collection(type)
2012-11-21 15:04:41 +00:00
end
end
2014-11-17 21:17:03 +00:00
private
2012-11-21 15:04:41 +00:00
2014-11-17 21:17:03 +00:00
def find_collection(type)
scope =
if type == 'users'
User.opened
else
type.classify.constantize.accessible_by(ability, :show)
end
scope.search(query).
search_order.
paginate(paginate_params)
2012-11-21 15:04:41 +00:00
end
2014-11-17 21:17:03 +00:00
2012-11-21 15:04:41 +00:00
end