Module: Trek::Scopes
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/trek/scopes.rb
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
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/concerns/trek/scopes.rb', line 7 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
19 20 21 22 23 |
# File 'app/controllers/concerns/trek/scopes.rb', line 19 def apply_scopes! @unscoped_objects = @objects @objects = apply_scopes(@objects, params[:scopes]) scope_counts end |
#available_scopes ⇒ Object
47 48 49 |
# File 'app/controllers/concerns/trek/scopes.rb', line 47 def available_scopes [] end |
#scope_counts ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/concerns/trek/scopes.rb', line 36 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
51 52 53 |
# File 'app/controllers/concerns/trek/scopes.rb', line 51 def scope_params params[:scopes]&.permit(*available_scopes) end |
#unscoped_objects ⇒ Object
32 33 34 |
# File 'app/controllers/concerns/trek/scopes.rb', line 32 def unscoped_objects @unscoped_objects || @objects end |