Class: Spree::PromotionCode::CodeBuilder
- Inherits:
-
Object
- Object
- Spree::PromotionCode::CodeBuilder
- Defined in:
- app/models/spree/promotion_code/code_builder.rb
Overview
A class responsible for building PromotionCodes
Instance Attribute Summary collapse
-
#base_code ⇒ Object
readonly
Returns the value of attribute base_code.
-
#num_codes ⇒ Object
readonly
Returns the value of attribute num_codes.
-
#promotion ⇒ Object
readonly
Returns the value of attribute promotion.
Instance Method Summary collapse
-
#build_promotion_codes ⇒ Object
Builds and returns an array of Spree::PromotionCode’s.
-
#initialize(promotion, base_code, num_codes) ⇒ CodeBuilder
constructor
Requres a
promotion
,base_code
andnum_codes
.
Constructor Details
#initialize(promotion, base_code, num_codes) ⇒ CodeBuilder
Requres a promotion
, base_code
and num_codes
promotion
Must be a Spree::Promotion. base_code
Must be a String. num_codes
Must be a positive integer greater than zero.
13 14 15 16 17 |
# File 'app/models/spree/promotion_code/code_builder.rb', line 13 def initialize promotion, base_code, num_codes @base_code = base_code @num_codes = num_codes @promotion = promotion end |
Instance Attribute Details
#base_code ⇒ Object (readonly)
Returns the value of attribute base_code.
3 4 5 |
# File 'app/models/spree/promotion_code/code_builder.rb', line 3 def base_code @base_code end |
#num_codes ⇒ Object (readonly)
Returns the value of attribute num_codes.
3 4 5 |
# File 'app/models/spree/promotion_code/code_builder.rb', line 3 def num_codes @num_codes end |
#promotion ⇒ Object (readonly)
Returns the value of attribute promotion.
3 4 5 |
# File 'app/models/spree/promotion_code/code_builder.rb', line 3 def promotion @promotion end |
Instance Method Details
#build_promotion_codes ⇒ Object
Builds and returns an array of Spree::PromotionCode’s
20 21 22 23 24 |
# File 'app/models/spree/promotion_code/code_builder.rb', line 20 def build_promotion_codes codes.map do |code| promotion.codes.build(value: code) end end |