Sha256: fbc9c711e6215f3461fb5ebafe4d6af90de1c62e16b4c73fa07cdc6e3006e528

Contents?: true

Size: 445 Bytes

Versions: 102

Compression:

Stored size: 445 Bytes

Contents

module Spree
  module Core
    module TokenGenerator
      def generate_token(model_class = Spree::Order)
        loop do
          token = "#{random_token}#{unique_ending}"
          break token unless model_class.exists?(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

102 entries across 102 versions & 1 rubygems

Version Path
spree_core-4.10.1 lib/spree/core/token_generator.rb
spree_core-4.10.0 lib/spree/core/token_generator.rb
spree_core-4.9.0 lib/spree/core/token_generator.rb
spree_core-4.8.3 lib/spree/core/token_generator.rb
spree_core-4.8.2 lib/spree/core/token_generator.rb
spree_core-4.7.3 lib/spree/core/token_generator.rb
spree_core-4.6.6 lib/spree/core/token_generator.rb
spree_core-4.5.5 lib/spree/core/token_generator.rb
spree_core-4.0.9 lib/spree/core/token_generator.rb
spree_core-4.1.15 lib/spree/core/token_generator.rb
spree_core-4.2.7 lib/spree/core/token_generator.rb
spree_core-4.3.3 lib/spree/core/token_generator.rb
spree_core-4.4.1 lib/spree/core/token_generator.rb
spree_core-4.5.4 lib/spree/core/token_generator.rb
spree_core-4.6.5 lib/spree/core/token_generator.rb
spree_core-4.7.2 lib/spree/core/token_generator.rb
spree_core-4.7.1 lib/spree/core/token_generator.rb
spree_core-4.6.4 lib/spree/core/token_generator.rb
spree_core-4.7.0 lib/spree/core/token_generator.rb
spree_core-4.6.3 lib/spree/core/token_generator.rb