Class: Api::Partner::AttachmentsFilter
- Inherits:
-
Object
- Object
- Api::Partner::AttachmentsFilter
- Defined in:
- app/filters/api/partner/attachments_filter.rb
Overview
Responsible for filtering and ordering attachments
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
Instance Method Summary collapse
- #build_collections ⇒ Object
- #filter(filter_params) ⇒ Object
-
#initialize(collections = nil) ⇒ AttachmentsFilter
constructor
A new instance of AttachmentsFilter.
- #order_by(order_params) ⇒ Object
- #to_collections ⇒ Object
Constructor Details
#initialize(collections = nil) ⇒ AttachmentsFilter
Returns a new instance of AttachmentsFilter.
9 10 11 12 |
# File 'app/filters/api/partner/attachments_filter.rb', line 9 def initialize(collections = nil) self.collections = collections unless collections.nil? @config = {} end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
6 7 8 |
# File 'app/filters/api/partner/attachments_filter.rb', line 6 def collections @collections end |
Instance Method Details
#build_collections ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/filters/api/partner/attachments_filter.rb', line 24 def build_collections if filter_params _filter_by_report_id _filter_by_name _filter_by_created_at _filter_by_finished_at _filter_by_status _filter_by_report_type end _order_by collections.group(:id) end |
#filter(filter_params) ⇒ Object
14 15 16 17 18 |
# File 'app/filters/api/partner/attachments_filter.rb', line 14 def filter(filter_params) return if filter_params.blank? config[:filter] = filter_params.fetch(:filter, {}) end |
#order_by(order_params) ⇒ Object
20 21 22 |
# File 'app/filters/api/partner/attachments_filter.rb', line 20 def order_by(order_params) config[:order_by] = order_params end |
#to_collections ⇒ Object
37 38 39 |
# File 'app/filters/api/partner/attachments_filter.rb', line 37 def to_collections build_collections.order(created_at: :desc) end |