Module: Trek::Scopes
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/trek/scopes.rb
Defined Under Namespace
Classes: NotAppliedError
Instance Method Summary collapse
- #apply_scopes(scope, filters) ⇒ Object
- #apply_scopes! ⇒ Object
- #available_scopes ⇒ Object
- #scope_counts ⇒ Object
- #scope_params ⇒ Object
- #unscoped_objects ⇒ Object
Instance Method Details
#apply_scopes(scope, filters) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/concerns/trek/scopes.rb', line 19 def apply_scopes(scope, filters) return scope if filters.blank? filters.each do |filter, value| next if value.blank? scope = scope.public_send(filter) if scope.respond_to?(filter) end scope end |
#apply_scopes! ⇒ Object
31 32 33 34 35 36 |
# File 'app/controllers/concerns/trek/scopes.rb', line 31 def apply_scopes! @scopes_applied = true @unscoped_objects = @objects @objects = apply_scopes(@objects, params[:scopes]) scope_counts end |
#available_scopes ⇒ Object
64 65 66 |
# File 'app/controllers/concerns/trek/scopes.rb', line 64 def available_scopes [] end |
#scope_counts ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/concerns/trek/scopes.rb', line 53 def scope_counts @scope_counts ||= begin Prosopite.pause if defined?(Prosopite) available_scopes.index_with do |scope| unscoped_objects.except(:limit, :offset).public_send(scope).count end ensure Prosopite.resume if defined?(Prosopite) end end |
#scope_params ⇒ Object
68 69 70 |
# File 'app/controllers/concerns/trek/scopes.rb', line 68 def scope_params params[:scopes]&.permit(*available_scopes) end |
#unscoped_objects ⇒ Object
49 50 51 |
# File 'app/controllers/concerns/trek/scopes.rb', line 49 def unscoped_objects @unscoped_objects || @objects end |