Class: Workarea::Pricing::Discount::CodeList
- Inherits:
-
Object
- Object
- Workarea::Pricing::Discount::CodeList
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/pricing/discount/code_list.rb
Instance Attribute Summary collapse
-
#count ⇒ Array
The number of codes to generate.
-
#expires_at ⇒ Array
When these codes expire.
-
#generation_completed_at ⇒ Array
The number of codes to generate.
-
#name ⇒ String
Name.
-
#prefix ⇒ String
String to prefix the generated codes.
-
#promo_codes ⇒ Enumerable<GeneratedPromoCode>
The list of promo codes that have been generated.
Instance Method Summary collapse
-
#generate_promo_codes! ⇒ Integer
This method creates a set of promo codes for this discount.
-
#generation_complete? ⇒ Boolean
Whether the list finished generating its codes.
-
#valid_codes?(test_codes) ⇒ Boolean
Whether any of the strings passed is a qualifying code for this discount.
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Instance Attribute Details
#count ⇒ Array
Returns the number of codes to generate.
25 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 25 field :count, type: Integer |
#expires_at ⇒ Array
Returns when these codes expire.
20 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 20 field :expires_at, type: Time |
#generation_completed_at ⇒ Array
Returns the number of codes to generate.
30 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 30 field :generation_completed_at, type: Time |
#name ⇒ String
Returns name.
10 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 10 field :name, type: String |
#prefix ⇒ String
Returns string to prefix the generated codes.
15 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 15 field :prefix, type: String |
#promo_codes ⇒ Enumerable<GeneratedPromoCode>
Returns the list of promo codes that have been generated.
42 43 44 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 42 has_many :promo_codes, class_name: 'Workarea::Pricing::Discount::GeneratedPromoCode', dependent: :delete |
Instance Method Details
#generate_promo_codes! ⇒ Integer
This method creates a set of promo codes for this discount.
52 53 54 55 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 52 def generate_promo_codes! count.times { generate_code } update_attributes!(generation_completed_at: Time.current) end |
#generation_complete? ⇒ Boolean
Whether the list finished generating its codes
61 62 63 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 61 def generation_complete? generation_completed_at.present? end |
#valid_codes?(test_codes) ⇒ Boolean
Whether any of the strings passed is a qualifying code for this discount. Used when checking discount conditions.
71 72 73 74 75 76 77 |
# File 'app/models/workarea/pricing/discount/code_list.rb', line 71 def valid_codes?(test_codes) promo_codes .not_expired .unused .where(:code.in => test_codes.map(&:to_s).map(&:downcase)) .exists? end |