Class: Api::V5::SearchIconsFilter

Inherits:
Object
  • Object
show all
Defined in:
app/filters/api/v5/search_icons_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collections = nil) ⇒ SearchIconsFilter

Returns a new instance of SearchIconsFilter.



10
11
12
13
# File 'app/filters/api/v5/search_icons_filter.rb', line 10

def initialize(collections = nil)
  self.collections = collections unless collections.nil?
  @config = {}
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



7
8
9
# File 'app/filters/api/v5/search_icons_filter.rb', line 7

def collections
  @collections
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'app/filters/api/v5/search_icons_filter.rb', line 8

def config
  @config
end

Instance Method Details

#as_json(context, _version, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/filters/api/v5/search_icons_filter.rb', line 35

def as_json(context, _version, options = {})
  options[:each_serializer] = Api::V5::DealSerializer
  options[:city_id] = config[:city_id] if config[:city_id].present?

  ActiveModelSerializers::SerializableResource.new(
    collections,
    {
      serialization_context: context,
      serializer: ActiveModel::Serializer::CollectionSerializer,
      adapter: :json_api,
    }.merge(options),
  ).as_json
end

#build_collectionsObject



27
28
29
30
31
32
33
# File 'app/filters/api/v5/search_icons_filter.rb', line 27

def build_collections
  self.collections = default_collections if collections.blank?
  build_by_city_id
  build_sort_by

  collections
end

#by_city_id(city_id) ⇒ Object



20
21
22
23
24
25
# File 'app/filters/api/v5/search_icons_filter.rb', line 20

def by_city_id(city_id)
  return self if city_id.blank?

  config[:city_id] = city_id
  self
end

#use_default_collectionsObject



15
16
17
18
# File 'app/filters/api/v5/search_icons_filter.rb', line 15

def use_default_collections
  self.collections = default_collections
  self
end