Class: Filterameter::RequestParameters
- Inherits:
-
Object
- Object
- Filterameter::RequestParameters
- Defined in:
- lib/filterameter/request_parameters.rb
Overview
Request Parameters
Value object that normalizes incoming request params and provides structured access to Filterameter filters, sorting, and pagination.
By default, filter and sort params are read from the configured filter-key namespace, while pagination params remain at the top level. When that namespace is disabled, all parameter types are read from the top level.
Exposes the configured pagination and sort parameter paths for link generation.
Instance Attribute Summary collapse
-
#pagination_page_path ⇒ Object
readonly
Returns the value of attribute pagination_page_path.
-
#pagination_size_path ⇒ Object
readonly
Returns the value of attribute pagination_size_path.
-
#sort_path ⇒ Object
readonly
Returns the value of attribute sort_path.
Instance Method Summary collapse
-
#filter_and_sort_params ⇒ Object
Returns the filter and sort params, excluding pagination.
-
#filter_params ⇒ Object
Returns the filter params, excluding sort and pagination.
-
#filter_sort_and_pagination_params ⇒ Object
Returns the filter, sort, and pagination params — the full set needed for link generation.
-
#initialize(params, declared_filter_parameter_names: nil) ⇒ RequestParameters
constructor
A new instance of RequestParameters.
-
#sort_params ⇒ Object
Returns the raw sort value from the request (a string, array of strings, or nil).
Constructor Details
#initialize(params, declared_filter_parameter_names: nil) ⇒ RequestParameters
Returns a new instance of RequestParameters.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/filterameter/request_parameters.rb', line 17 def initialize(params, declared_filter_parameter_names: nil) @params = normalize(params) @declared_filter_parameter_names = normalize_declared_names(declared_filter_parameter_names) config = Filterameter.configuration @filter_key = config.filter_key @sort_path = sort_parameter_path.freeze @pagination_page_path = config.pagination_page_param.dup.freeze @pagination_size_path = config.pagination_size_param.dup.freeze @pagination_roots = pagination_roots.freeze end |
Instance Attribute Details
#pagination_page_path ⇒ Object (readonly)
Returns the value of attribute pagination_page_path.
15 16 17 |
# File 'lib/filterameter/request_parameters.rb', line 15 def pagination_page_path @pagination_page_path end |
#pagination_size_path ⇒ Object (readonly)
Returns the value of attribute pagination_size_path.
15 16 17 |
# File 'lib/filterameter/request_parameters.rb', line 15 def pagination_size_path @pagination_size_path end |
#sort_path ⇒ Object (readonly)
Returns the value of attribute sort_path.
15 16 17 |
# File 'lib/filterameter/request_parameters.rb', line 15 def sort_path @sort_path end |
Instance Method Details
#filter_and_sort_params ⇒ Object
Returns the filter and sort params, excluding pagination.
39 40 41 42 43 44 45 46 47 |
# File 'lib/filterameter/request_parameters.rb', line 39 def filter_and_sort_params params = if @filter_key @params.fetch(filter_key) { @params.fetch(filter_key.to_s, {}) } else flat_filter_and_sort_params end params.deep_dup end |
#filter_params ⇒ Object
Returns the filter params, excluding sort and pagination.
29 30 31 |
# File 'lib/filterameter/request_parameters.rb', line 29 def filter_params filter_and_sort_params.except(:sort) end |
#filter_sort_and_pagination_params ⇒ Object
Returns the filter, sort, and pagination params — the full set needed for link generation.
50 51 52 53 54 |
# File 'lib/filterameter/request_parameters.rb', line 50 def filter_sort_and_pagination_params return flat_query_params.deep_dup unless @filter_key @params.slice(filter_key, *@pagination_roots).deep_dup end |
#sort_params ⇒ Object
Returns the raw sort value from the request (a string, array of strings, or nil).
34 35 36 |
# File 'lib/filterameter/request_parameters.rb', line 34 def sort_params filter_and_sort_params[:sort] end |