rosa-build/app/models/search.rb

32 lines
729 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
# scope_policy(type.classify.constantize).accessible_by(ability, :show)
"#{klass}Policy::Scope".classify.constantize.new(user, klass).show
# policy_scope(type.classify.constantize).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