module GraphQR::ApplyScopes
The ApplyScopes
module defines a way of applying model scopes in the GraphQL universe it is based on the has_scope gem, but simplified for more basic usage
Public Instance Methods
apply_scopes(target, scopes)
click to toggle source
This method is a parallel to the one offerend by the has_scope
gem. A big difference in this case is the necessity of the second parameter (normally it only takes one).
Params:¶ ↑
target
: the ActiveRecordRelation that will be filtered using scopes
scopes
: a hash of scopes and their values, those only accept Array, String, Integer or Boolean types. Hash scopes are not yet supported
Example:¶ ↑
apply_scopes(User, { with_id: [1,2,3], order_by_name: true} )
# File lib/graphqr/apply_scopes.rb, line 24 def apply_scopes(target, scopes) parsed_scopes = parse_scopes(scopes.to_h) parsed_scopes.each do |scope, value| target = call_scope(target, scope, value) end target end