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.2.4 lib/spree/core/token_generator.rb
spree_core-3.7.14.1 lib/spree/core/token_generator.rb
spree_core-4.2.3.1 lib/spree/core/token_generator.rb
spree_core-4.1.13.1 lib/spree/core/token_generator.rb
spree_core-4.0.7.1 lib/spree/core/token_generator.rb
spree_core-4.2.3 lib/spree/core/token_generator.rb
spree_core-4.2.2 lib/spree/core/token_generator.rb
spree_core-4.2.1 lib/spree/core/token_generator.rb
spree_core-4.0.7 lib/spree/core/token_generator.rb
spree_core-3.7.14 lib/spree/core/token_generator.rb
spree_core-4.2.0 lib/spree/core/token_generator.rb
spree_core-4.2.0.rc5 lib/spree/core/token_generator.rb
spree_core-4.2.0.rc4 lib/spree/core/token_generator.rb
spree_core-4.2.0.rc3 lib/spree/core/token_generator.rb
spree_core-4.1.13 lib/spree/core/token_generator.rb
spree_core-4.0.6 lib/spree/core/token_generator.rb
spree_core-4.2.0.rc2 lib/spree/core/token_generator.rb
spree_core-3.7.13 lib/spree/core/token_generator.rb
spree_core-4.0.5 lib/spree/core/token_generator.rb
spree_core-4.1.12 lib/spree/core/token_generator.rb