Sha256: cfc55141768717842474e8aaa5dd55b941e7397e101fe9c73c518b32aba9391f
Contents?: true
Size: 1.01 KB
Versions: 51
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true module Solidus module Migrations class RenameGateways DEFAULT_MAPPING = { 'Spree::Gateway' => 'Spree::PaymentMethod::CreditCard', 'Spree::Gateway::Bogus' => 'Spree::PaymentMethod::BogusCreditCard', 'Spree::Gateway::BogusSimple' => 'Spree::PaymentMethod::SimpleBogusCreditCard' } attr_reader :gateway_mapping def initialize(gateway_mapping = DEFAULT_MAPPING) @gateway_mapping = gateway_mapping end def up gateway_mapping.inject(0) do |count, mapping| count + update(from: mapping[0], to: mapping[1]) end end def down gateway_mapping.inject(0) do |count, mapping| count + update(from: mapping[1], to: mapping[0]) end end private def update(from:, to:) ActiveRecord::Base.connection.update <<-SQL.strip_heredoc UPDATE spree_payment_methods SET type = '#{to}' WHERE type = '#{from}'; SQL end end end end
Version data entries
51 entries across 51 versions & 2 rubygems