Class: PackAPI::Mapping::FilterMap
- Inherits:
-
Object
- Object
- PackAPI::Mapping::FilterMap
- Defined in:
- lib/pack_api/mapping/filter_map.rb
Overview
This class is responsible for transforming API filter names into model filters. It also produces filter definitions in API terms for those filters that are supported by the model.
Instance Attribute Summary collapse
-
#attribute_map_class ⇒ Object
readonly
Returns the value of attribute attribute_map_class.
-
#filter_factory ⇒ Object
readonly
Returns the value of attribute filter_factory.
Instance Method Summary collapse
- #filter_definitions(filter_names: nil) ⇒ Object
- #from_api_filters(api_filters) ⇒ Object
-
#initialize(filter_factory:, attribute_map_class: nil) ⇒ FilterMap
constructor
A new instance of FilterMap.
Constructor Details
#initialize(filter_factory:, attribute_map_class: nil) ⇒ FilterMap
Returns a new instance of FilterMap.
10 11 12 13 |
# File 'lib/pack_api/mapping/filter_map.rb', line 10 def initialize(filter_factory:, attribute_map_class: nil) @filter_factory = filter_factory @attribute_map_class = attribute_map_class end |
Instance Attribute Details
#attribute_map_class ⇒ Object (readonly)
Returns the value of attribute attribute_map_class.
8 9 10 |
# File 'lib/pack_api/mapping/filter_map.rb', line 8 def attribute_map_class @attribute_map_class end |
#filter_factory ⇒ Object (readonly)
Returns the value of attribute filter_factory.
8 9 10 |
# File 'lib/pack_api/mapping/filter_map.rb', line 8 def filter_factory @filter_factory end |
Instance Method Details
#filter_definitions(filter_names: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/pack_api/mapping/filter_map.rb', line 20 def filter_definitions(filter_names: nil, **) supported_filters.filter_map do |filter_name, filter_class| next if filter_names&.exclude?(filter_name) api_attribute_filter_name_map.key?(filter_name) ? attribute_filter_definition(filter_name, filter_class) : other_filter_definition(filter_name, filter_class, **) end end |
#from_api_filters(api_filters) ⇒ Object
15 16 17 18 |
# File 'lib/pack_api/mapping/filter_map.rb', line 15 def from_api_filters(api_filters) validate(api_filters) transform_api_attribute_filters(api_filters).merge(transform_api_custom_filters(api_filters)) end |