Method: Brainstem::Presenter#apply_filters_to_scope
- Defined in:
- lib/brainstem/presenter.rb
#apply_filters_to_scope(scope, user_params, options) ⇒ Object
Given user params, build a hash of validated filter names to their unsanitized arguments.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/brainstem/presenter.rb', line 188 def apply_filters_to_scope(scope, user_params, ) helper_instance = fresh_helper_instance requested_filters = extract_filters(user_params, ) requested_filters.each do |filter_name, filter_arg| filter_lambda = configuration[:filters][filter_name][:value] args_for_filter_lambda = [filter_arg] args_for_filter_lambda << requested_filters if configuration[:filters][filter_name][:include_params] if filter_lambda scope = helper_instance.instance_exec(scope, *args_for_filter_lambda, &filter_lambda) else scope = scope.send(filter_name, *args_for_filter_lambda) end end scope end |