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

- (BatchBuilder) initialize(promotion_code_batch)

Returns a new instance of BatchBuilder



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

def initialize(promotion_code_batch)
  @promotion_code_batch = promotion_code_batch
end

Instance Attribute Details

- (Object) promotion_code_batch (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

- (Object) build_promotion_codes



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

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