Module: GraphQR::ApplyScopes
- Included in:
- Base
- Defined in:
- lib/graphqr/apply_scopes.rb
Overview
The ApplyScopes module defines a way of applying model scopes in the GraphQL universe it is based on the [has_scope](github.com/plataformatec/has_scope/) gem, but simplified for more basic usage
Instance Method Summary collapse
-
#apply_scopes(target, scopes) ⇒ Object
This method is a parallel to the one offerend by the ‘has_scope` gem.
Instance Method Details
#apply_scopes(target, scopes) ⇒ Object
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} ) “`
24 25 26 27 28 29 30 31 32 |
# 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 |