Skip to content

Commit f15b78c

Browse files
committed
Promotions: Inject logger to promotion migrator
Let's remove this implicit dependency.
1 parent 844bdd6 commit f15b78c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

promotions/lib/solidus_promotions/promotion_migrator.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# frozen_string_literal: true
22

3+
require "logger"
4+
35
module SolidusPromotions
46
class PromotionMigrator
57
PROMOTION_IGNORED_ATTRIBUTES = ["id", "type", "promotion_category_id", "promotion_id"]
68

7-
attr_reader :promotion_map
9+
attr_reader :promotion_map, :logger
810

9-
def initialize(promotion_map)
11+
def initialize(promotion_map, logger: nil)
12+
@logger = logger || Logger.new($stdout)
1013
@promotion_map = promotion_map
1114
end
1215

@@ -78,7 +81,7 @@ def copy_promotion(old_promotion)
7881
def generate_new_benefits(old_promotion_action)
7982
promo_action_config = promotion_map[:actions][old_promotion_action.class]
8083
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")
8285
return nil
8386
end
8487
promo_action_config.call(old_promotion_action)
@@ -87,7 +90,7 @@ def generate_new_benefits(old_promotion_action)
8790
def generate_new_promotion_conditions(old_promotion_rule)
8891
new_promo_condition_class = promotion_map[:conditions][old_promotion_rule.class]
8992
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")
9194
[]
9295
elsif new_promo_condition_class.respond_to?(:call)
9396
new_promo_condition_class.call(old_promotion_rule)

promotions/lib/tasks/solidus_promotions/migrate_existing_promotions.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace :solidus_promotions do
77
task migrate_existing_promotions: :environment do
88
require "solidus_promotions/promotion_map"
99

10-
SolidusPromotions::PromotionMigrator.new(SolidusPromotions::PROMOTION_MAP).call
10+
SolidusPromotions::PromotionMigrator.new(SolidusPromotions::PROMOTION_MAP, logger: Rails.logger).call
1111
end
1212
end

0 commit comments

Comments
 (0)