Module: FetcheableOnApi::Filterable::ClassMethods
- Defined in:
- lib/fetcheable_on_api/filterable.rb
Overview
Class methods made available to controllers when Filterable is included.
Instance Method Summary collapse
-
#filter_by(*attrs) ⇒ Object
Define one or more filterable attributes for the controller.
Instance Method Details
#filter_by(*attrs) ⇒ Object
Define one or more filterable attributes for the controller.
This method configures which model attributes can be filtered via query parameters and how those filters should be processed.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/fetcheable_on_api/filterable.rb', line 139 def filter_by(*attrs) = attrs. .symbolize_keys! # Validate that only supported options are provided .assert_valid_keys(:as, :class_name, :with, :format, :association) # Create a new configuration hash to avoid modifying parent class config self.filters_configuration = filters_configuration.dup attrs.each do |attr| # Initialize default configuration for this attribute filters_configuration[attr] ||= { as: [:as] || attr } # Merge in the provided options filters_configuration[attr].merge!() end end |