Class: Api::Partner::AttachmentsFilter

Inherits:
Object
  • Object
show all
Defined in:
app/filters/api/partner/attachments_filter.rb

Overview

Responsible for filtering and ordering attachments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collections = nil) ⇒ AttachmentsFilter

Returns a new instance of AttachmentsFilter.

Parameters:

  • collections (Attachment) (defaults to: nil)

    Attachment relations



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

#collectionsObject

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_collectionsObject



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_collectionsObject



37
38
39
# File 'app/filters/api/partner/attachments_filter.rb', line 37

def to_collections
  build_collections.order(created_at: :desc)
end