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

Version Path
solidus_core-2.8.6 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.6.6 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.7.4 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.8.5 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.7.3 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.6.5 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.5.2 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.8.4 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.8.3 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.7.2 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.6.4 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.8.2 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.8.1 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.5.1 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.6.3 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.8.0 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.7.1 lib/solidus/migrations/rename_gateways.rb
solidus_core-2.6.2 lib/solidus/migrations/rename_gateways.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 lib/solidus/migrations/rename_gateways.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 lib/solidus/migrations/rename_gateways.rb