Class: Spree::PromotionCode::BatchBuilder
- Inherits:
-
Object
- Object
- Spree::PromotionCode::BatchBuilder
- Defined in:
- app/models/spree/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) }
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.
13 14 15 16 17 |
# File 'app/models/spree/promotion_code/batch_builder.rb', line 13 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.
4 5 6 |
# File 'app/models/spree/promotion_code/batch_builder.rb', line 4 def @options end |
#promotion_code_batch ⇒ Object (readonly)
Returns the value of attribute promotion_code_batch.
4 5 6 |
# File 'app/models/spree/promotion_code/batch_builder.rb', line 4 def promotion_code_batch @promotion_code_batch end |
Instance Method Details
#build_promotion_codes ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/spree/promotion_code/batch_builder.rb', line 19 def build_promotion_codes generate_random_codes promotion_code_batch.update!(state: "completed") rescue StandardError => error promotion_code_batch.update!( error: error.inspect, state: "failed" ) raise error end |