Class: Api::Partner::UpdatedInventoryFilter
- Inherits:
-
Object
- Object
- Api::Partner::UpdatedInventoryFilter
- Defined in:
- app/filters/api/partner/updated_inventory_filter.rb
Overview
Responsible for filtering updated inventories data for partner API This class provides various filtering capabilities for inventory collections based on dates, times, and reasons.
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
Instance Method Summary collapse
-
#build_collections ⇒ ActiveRecord::Relation
Build the filtered collections by applying all active filters.
-
#filter(filter_par) ⇒ Hash?
Set the filter parameters.
-
#initialize(collections = nil) ⇒ UpdatedInventoryFilter
constructor
Initialize a new filter instance.
-
#to_collections ⇒ ActiveRecord::Relation
Returns the final filtered and ordered collection.
Constructor Details
#initialize(collections = nil) ⇒ UpdatedInventoryFilter
Initialize a new filter instance
15 16 17 18 |
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 15 def initialize(collections = nil) self.collections = collections unless collections.nil? @config = {} end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
11 12 13 |
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 11 def collections @collections end |
#error_message ⇒ Object
Returns the value of attribute error_message.
11 12 13 |
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 11 def @error_message end |
Instance Method Details
#build_collections ⇒ ActiveRecord::Relation
Build the filtered collections by applying all active filters
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 31 def build_collections if filter_params _filter_by_start_date _filter_by_end_date _filter_by_start_time _filter_by_end_time _filter_by_date_range _filter_by_reason end collections end |
#filter(filter_par) ⇒ Hash?
Set the filter parameters
23 24 25 26 27 |
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 23 def filter(filter_par) return if filter_par.blank? config[:filter] = filter_par end |
#to_collections ⇒ ActiveRecord::Relation
Returns the final filtered and ordered collection
45 46 47 |
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 45 def to_collections build_collections.order(created_at: :desc) end |