1
1
# frozen_string_literal: true
2
2
3
+ require "logger"
4
+
3
5
module SolidusPromotions
4
6
class PromotionMigrator
5
7
PROMOTION_IGNORED_ATTRIBUTES = [ "id" , "type" , "promotion_category_id" , "promotion_id" ]
6
8
7
- attr_reader :promotion_map
9
+ attr_reader :promotion_map , :logger
8
10
9
- def initialize ( promotion_map )
11
+ def initialize ( promotion_map , logger : nil )
12
+ @logger = logger || Logger . new ( $stdout)
10
13
@promotion_map = promotion_map
11
14
end
12
15
@@ -78,7 +81,7 @@ def copy_promotion(old_promotion)
78
81
def generate_new_benefits ( old_promotion_action )
79
82
promo_action_config = promotion_map [ :actions ] [ old_promotion_action . class ]
80
83
if promo_action_config . nil?
81
- Rails . logger . info ( "#{ old_promotion_action . class } is not supported" )
84
+ logger . info ( "#{ old_promotion_action . class } is not supported" )
82
85
return nil
83
86
end
84
87
promo_action_config . call ( old_promotion_action )
@@ -87,7 +90,7 @@ def generate_new_benefits(old_promotion_action)
87
90
def generate_new_promotion_conditions ( old_promotion_rule )
88
91
new_promo_condition_class = promotion_map [ :conditions ] [ old_promotion_rule . class ]
89
92
if new_promo_condition_class . nil?
90
- Rails . logger . info ( "#{ old_promotion_rule . class } is not supported" )
93
+ logger . info ( "#{ old_promotion_rule . class } is not supported" )
91
94
[ ]
92
95
elsif new_promo_condition_class . respond_to? ( :call )
93
96
new_promo_condition_class . call ( old_promotion_rule )
0 commit comments