Class: Grape::Validations::ParamScopeTracker
- Inherits:
-
Object
- Object
- Grape::Validations::ParamScopeTracker
- Defined in:
- lib/grape/validations/param_scope_tracker.rb
Overview
Holds per-request mutable state that must not live on shared ParamsScope instances. Both trackers are identity-keyed hashes so that ParamsScope objects can serve as keys without relying on value equality.
Lifecycle is managed by Endpoint#run_validators via .track. Use .current to access the instance for the running request.
Constant Summary collapse
- FIBER_KEY =
Fiber-local key used to store the current tracker. Fiber[] (Ruby 3.0+) is used instead of Thread.current[] so that fiber-based servers (e.g. Falcon with async) isolate each request’s tracker within its own fiber rather than sharing state across all fibers running on the same thread.
:grape_param_scope_tracker- EMPTY_PARAMS =
[].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #index_for(scope) ⇒ Object
-
#qualifying_params(scope) ⇒ Object
Returns qualifying params for
scope, or EMPTY_PARAMS if none were stored. - #store_index(scope, index) ⇒ Object
- #store_qualifying_params(scope, params) ⇒ Object
Class Method Details
.current ⇒ Object
28 29 30 |
# File 'lib/grape/validations/param_scope_tracker.rb', line 28 def self.current Fiber[FIBER_KEY] end |
Instance Method Details
#index_for(scope) ⇒ Object
36 37 38 |
# File 'lib/grape/validations/param_scope_tracker.rb', line 36 def index_for(scope) index_tracker[scope] end |
#qualifying_params(scope) ⇒ Object
Returns qualifying params for scope, or EMPTY_PARAMS if none were stored. Note: an explicitly stored empty array and “never stored” are treated identically by callers (both yield a blank result that falls through to the parent params).
43 44 45 |
# File 'lib/grape/validations/param_scope_tracker.rb', line 43 def (scope) .fetch(scope, EMPTY_PARAMS) end |
#store_index(scope, index) ⇒ Object
32 33 34 |
# File 'lib/grape/validations/param_scope_tracker.rb', line 32 def store_index(scope, index) index_tracker.store(scope, index) end |
#store_qualifying_params(scope, params) ⇒ Object
47 48 49 |
# File 'lib/grape/validations/param_scope_tracker.rb', line 47 def (scope, params) .store(scope, params) end |