Class: Api::V5::PromotionsFilter

Inherits:
Object
  • Object
show all
Includes:
PaginationConcernFilter
Defined in:
app/filters/api/v5/promotions_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PaginationConcernFilter

#page_number, #per_page

Constructor Details

#initialize(collections = nil) ⇒ PromotionsFilter

Returns a new instance of PromotionsFilter.



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

def initialize(collections = nil)
  self.collections = collections unless collections.nil?
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



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

def collections
  @collections
end

Instance Method Details

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

Examples:

options = {}

Parameters:

  • context (Struct)

    Serialization Context

  • version (Integer)

    ApiV5::Constants::DEFAULT_MINOR_VERSION

  • options (Hash) (defaults to: {})
    • include options to be passed to Serializer instance



31
32
33
34
35
36
37
38
# File 'app/filters/api/v5/promotions_filter.rb', line 31

def as_json(context, version, options = {})
  options[:each_serializer] = Api::V5::PromotionSerializer
  ActiveModelSerializers::SerializableResource.new(collections,
                                                   { serialization_context: context,
                                                     serializer: ActiveModel::Serializer::CollectionSerializer,
                                                     adapter: :json_api }.merge(options)
                                                  ).as_json
end

#created_or_updated_after(timestamp) ⇒ Object



19
20
21
22
23
# File 'app/filters/api/v5/promotions_filter.rb', line 19

def created_or_updated_after(timestamp)
  return self if timestamp.blank?
  self.collections = collections.where('updated_at >= ? OR created_at >= ?', timestamp, timestamp)
  self
end

#init_defaultObject



14
15
16
17
# File 'app/filters/api/v5/promotions_filter.rb', line 14

def init_default
  self.collections = ::Promotion.where(active: true).order('id DESC')
  self
end