Sha256: 81d12909d295ddc5db9e9a721c0c101bc85add1effb9ae849d4f032908d30bcd

Contents?: true

Size: 541 Bytes

Versions: 7

Compression:

Stored size: 541 Bytes

Contents

require 'dm-core'

require 'digest/sha1'

module DataMapper
  class Property
    class APIKey < String

      # The amount of random seed data to use to generate tha API Key
      PADDING = 256

      length 40
      unique true
      default proc { APIKey.generate }

      #
      # Generates a new API Key.
      #
      # @return [String]
      #   The new API Key.
      #
      def self.generate
        sha1 = Digest::SHA1.new

        PADDING.times { sha1 << rand(256).chr }
        return sha1.hexdigest
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ardm-types-1.2.3 lib/dm-types/api_key.rb
ardm-types-1.2.2 lib/dm-types/api_key.rb
dm-types-1.2.2 lib/dm-types/api_key.rb
dm-types-1.2.1 lib/dm-types/api_key.rb
dm-types-1.2.0 lib/dm-types/api_key.rb
dm-types-1.2.0.rc2 lib/dm-types/api_key.rb
dm-types-1.2.0.rc1 lib/dm-types/api_key.rb