Class: Api::V5::PromotionsFilter
- Inherits:
-
Object
- Object
- Api::V5::PromotionsFilter
- Includes:
- PaginationConcernFilter
- Defined in:
- app/filters/api/v5/promotions_filter.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
Instance Method Summary collapse
- #as_json(context, version, options = {}) ⇒ Object
- #created_or_updated_after(timestamp) ⇒ Object
- #init_default ⇒ Object
-
#initialize(collections = nil) ⇒ PromotionsFilter
constructor
A new instance of PromotionsFilter.
Methods included from PaginationConcernFilter
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
#collections ⇒ Object
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
31 32 33 34 35 36 37 38 |
# File 'app/filters/api/v5/promotions_filter.rb', line 31 def as_json(context, version, = {}) [:each_serializer] = Api::V5::PromotionSerializer ActiveModelSerializers::SerializableResource.new(collections, { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api }.merge() ).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() return self if .blank? self.collections = collections.where('updated_at >= ? OR created_at >= ?', , ) self end |
#init_default ⇒ Object
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 |