Class: Spree::PromotionCode::BatchBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/promotion_code/batch_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(promotion_code_batch) ⇒ BatchBuilder

Returns a new instance of BatchBuilder



11
12
13
# File 'app/models/spree/promotion_code/batch_builder.rb', line 11

def initialize(promotion_code_batch)
  @promotion_code_batch = promotion_code_batch
end

Instance Attribute Details

#promotion_code_batchObject (readonly)

Returns the value of attribute promotion_code_batch



2
3
4
# File 'app/models/spree/promotion_code/batch_builder.rb', line 2

def promotion_code_batch
  @promotion_code_batch
end

Instance Method Details

#build_promotion_codesObject



15
16
17
18
19
20
21
22
23
24
# File 'app/models/spree/promotion_code/batch_builder.rb', line 15

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