Sha256: da5365e937efcf74aa3b9fa8019a03077401700945139285880ca1043f66514e

Contents?: true

Size: 890 Bytes

Versions: 26

Compression:

Stored size: 890 Bytes

Contents

module Workarea
  module Pricing
    class Discount
      # Represents an instance of redemption for a {Discount}.
      # Used for calculating single use discounts.
      #
      class Redemption
        include ApplicationDocument

        # @!attribute email
        #   @return [String] the email that received the discount
        #
        field :email, type: String

        # @!attribute discount
        #   @return [Discount] the discount
        #
        belongs_to :discount,
          class_name: 'Workarea::Pricing::Discount'

        scope :recent, -> { desc(:created_at) }
        index({ discount_id: 1, email: 1 })
        index({ discount_id: 1, created_at: -1 }, { background: true })

        before_validation :downcase_email

        private

        def downcase_email
          self.email = email.downcase if email.present?
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.26 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.25 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.23 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.22 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.21 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.20 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.19 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.18 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.17 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.16 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.15 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.14 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.13 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.12 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.11 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.10 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.9 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.8 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.7 app/models/workarea/pricing/discount/redemption.rb