Sha256: 07de4e88360da42da9cfeb5d4aa5e6f052c83c8f9eeeebcc26b3329f1763298f

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

require 'solidus_support/version'
require 'solidus_support/migration'
require 'solidus_support/engine_extensions'
require 'solidus_core'

module SolidusSupport
  class << self
    def solidus_gem_version
      if Spree.respond_to?(:solidus_gem_version)
        Spree.solidus_gem_version
      elsif Spree.respond_to?(:gem_version)
        # 1.1 doesn't have solidus_gem_version
        Gem::Version.new(Spree.solidus_version)
      else
        # 1.0 doesn't have gem_version
        Gem::Specification.detect { |x| x.name == 'solidus_core' }.version
      end
    end

    def reset_spree_preferences_deprecated?
      first_version_without_reset = Gem::Requirement.new('>= 2.9')
      first_version_without_reset.satisfied_by?(solidus_gem_version)
    end

    def new_gateway_code?
      first_version_with_new_gateway_code = Gem::Requirement.new('>= 2.3')
      first_version_with_new_gateway_code.satisfied_by?(solidus_gem_version)
    end

    def payment_source_parent_class
      if new_gateway_code?
        Spree::PaymentSource
      else
        Spree::Base
      end
    end

    def payment_method_parent_class(credit_card: false)
      if new_gateway_code?
        if credit_card
          Spree::PaymentMethod::CreditCard
        else
          Spree::PaymentMethod
        end
      else
        Spree::Gateway
      end
    end

    def frontend_available?
      defined?(Spree::Frontend::Engine)
    end

    def backend_available?
      defined?(Spree::Backend::Engine)
    end

    def api_available?
      defined?(Spree::Api::Engine)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_support-0.4.1 lib/solidus_support.rb
solidus_support-0.4.0 lib/solidus_support.rb