Class: Api::V5::SearchIconsFilter
- Inherits:
-
Object
- Object
- Api::V5::SearchIconsFilter
- Defined in:
- app/filters/api/v5/search_icons_filter.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #as_json(context, _version, options = {}) ⇒ Object
- #build_collections ⇒ Object
- #by_city_id(city_id) ⇒ Object
-
#initialize(collections = nil) ⇒ SearchIconsFilter
constructor
A new instance of SearchIconsFilter.
- #use_default_collections ⇒ Object
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
#collections ⇒ Object
Returns the value of attribute collections.
7 8 9 |
# File 'app/filters/api/v5/search_icons_filter.rb', line 7 def collections @collections end |
#config ⇒ Object (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, = {}) [:each_serializer] = Api::V5::DealSerializer [: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(), ).as_json end |
#build_collections ⇒ Object
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_collections ⇒ Object
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 |