Sha256: 087f807e1b2b5c57f34cae86fdfccc516e851c13f5663d86ee87d5bc4e39edbd

Contents?: true

Size: 457 Bytes

Versions: 66

Compression:

Stored size: 457 Bytes

Contents

module Spree
  module Core
    module TokenGenerator
      def generate_guest_token(model_class = Spree::Order)
        loop do
          token = "#{random_token}#{unique_ending}"
          break token unless model_class.exists?(guest_token: token)
        end
      end

      private

      def random_token
        SecureRandom.urlsafe_base64(nil, false)
      end

      def unique_ending
        (Time.now.to_f * 1000).to_i
      end
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
spree_core-3.4.6 lib/spree/core/token_generator.rb
spree_core-3.2.9 lib/spree/core/token_generator.rb
spree_core-3.1.14 lib/spree/core/token_generator.rb
spree_core-3.6.6 lib/spree/core/token_generator.rb
spree_core-3.6.5 lib/spree/core/token_generator.rb
spree_core-3.6.4 lib/spree/core/token_generator.rb
spree_core-3.6.3 lib/spree/core/token_generator.rb
spree_core-3.6.2 lib/spree/core/token_generator.rb
spree_core-3.6.1 lib/spree/core/token_generator.rb
spree_core-3.6.0 lib/spree/core/token_generator.rb
spree_core-3.5.0 lib/spree/core/token_generator.rb
spree_core-3.3.6 lib/spree/core/token_generator.rb
spree_core-3.2.8 lib/spree/core/token_generator.rb
spree_core-3.1.13 lib/spree/core/token_generator.rb
spree_core-3.6.0.rc1 lib/spree/core/token_generator.rb
spree_core-3.5.0.rc2 lib/spree/core/token_generator.rb
spree_core-3.5.0.rc1 lib/spree/core/token_generator.rb
spree_core-3.4.5 lib/spree/core/token_generator.rb
spree_core-3.3.5 lib/spree/core/token_generator.rb
spree_core-3.4.4 lib/spree/core/token_generator.rb