Sha256: adb7579da6652cad471674511fbbd613b90ac2794cd384309bbc0789a0373c94

Contents?: true

Size: 818 Bytes

Versions: 2

Compression:

Stored size: 818 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 })

        before_validation :downcase_email

        private

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-core-3.5.0 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.0.beta.1 app/models/workarea/pricing/discount/redemption.rb