Class: SolidusFriendlyPromotions::PromotionCode::BatchBuilder
- Inherits:
-
Object
- Object
- SolidusFriendlyPromotions::PromotionCode::BatchBuilder
- Defined in:
- app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ random_code_length: 6, batch_size: 1000, sample_characters: ("a".."z").to_a + (2..9).to_a.map(&:to_s) }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#promotion_code_batch ⇒ Object
readonly
Returns the value of attribute promotion_code_batch.
Instance Method Summary collapse
- #build_promotion_codes ⇒ Object
-
#initialize(promotion_code_batch, options = {}) ⇒ BatchBuilder
constructor
A new instance of BatchBuilder.
Constructor Details
#initialize(promotion_code_batch, options = {}) ⇒ BatchBuilder
Returns a new instance of BatchBuilder.
16 17 18 19 20 |
# File 'app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb', line 16 def initialize(promotion_code_batch, = {}) @promotion_code_batch = promotion_code_batch .assert_valid_keys(*DEFAULT_OPTIONS.keys) @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb', line 6 def @options end |
#promotion_code_batch ⇒ Object (readonly)
Returns the value of attribute promotion_code_batch.
6 7 8 |
# File 'app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb', line 6 def promotion_code_batch @promotion_code_batch end |
Instance Method Details
#build_promotion_codes ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb', line 22 def build_promotion_codes generate_random_codes promotion_code_batch.update!(state: "completed") rescue => e promotion_code_batch.update!( error: e.inspect, state: "failed" ) raise e end |