rosa-build/app/models/search.rb

30 lines
585 B
Ruby
Raw Normal View History

class Search < Struct.new(:query, :user, :paginate_params)
2014-11-17 21:17:03 +00:00
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
klass = type.classify.constantize
2015-04-14 21:21:37 +01:00
"#{klass}Policy::Scope".constantize.new(user, klass).show
2014-11-17 21:17:03 +00:00
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
end