Class: Spree::PromotionBuilder

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/spree/promotion_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, promotion_attributes = {}) ⇒ PromotionBuilder

Returns a new instance of PromotionBuilder.

Parameters:

  • promotion_attrs (Hash)

    The desired attributes for the newly promotion

  • attributes (Hash) (defaults to: {})

    The desired attributes for this builder

  • user (Spree::User)

    The user who triggered this promotion build



19
20
21
22
# File 'app/models/spree/promotion_builder.rb', line 19

def initialize(attributes={}, promotion_attributes={})
  @promotion = Spree::Promotion.new(promotion_attributes)
  super(attributes)
end

Instance Attribute Details

#base_codeObject

Returns the value of attribute base_code.



5
6
7
# File 'app/models/spree/promotion_builder.rb', line 5

def base_code
  @base_code
end

#number_of_codesObject

Returns the value of attribute number_of_codes.



5
6
7
# File 'app/models/spree/promotion_builder.rb', line 5

def number_of_codes
  @number_of_codes
end

#promotionObject (readonly)

Returns the value of attribute promotion.



4
5
6
# File 'app/models/spree/promotion_builder.rb', line 4

def promotion
  @promotion
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'app/models/spree/promotion_builder.rb', line 5

def user
  @user
end

Instance Method Details

#performObject



24
25
26
27
28
29
30
31
32
# File 'app/models/spree/promotion_builder.rb', line 24

def perform
  if can_build_codes?
    @promotion.codes = code_builder.build_promotion_codes
  end

  return false unless valid?

  @promotion.save
end