Sha256: eb0ea1fb77cc15bbddf508eae4e7a9030539437c47cd60e98e78f979d8102351

Contents?: true

Size: 534 Bytes

Versions: 5

Compression:

Stored size: 534 Bytes

Contents

require 'zlib'

module NamedSeeds
  module DSL

    MAX_ID = 2 ** 30 - 1

    # Copy of ActiveRecord::Fixtures.identify method.
    # Returns a consistent, platform-independent identifier for +label+.
    # Integer identifiers are values less than 2^30.
    # UUIDs are RFC 4122 version 5 SHA-1 hashes.
    #
    def identify(label, column_type = :integer)
      if column_type == :uuid
        NamedSeeds.uuid_v5(label)
      else
        Zlib.crc32(label.to_s) % MAX_ID
      end
    end
    alias_method :id, :identify

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
named_seeds-2.2.1 lib/named_seeds/dsl.rb
named_seeds-2.2.0 lib/named_seeds/dsl.rb
named_seeds-2.1.0 lib/named_seeds/dsl.rb
named_seeds-2.0.1 lib/named_seeds/dsl.rb
named_seeds-2.0.0 lib/named_seeds/dsl.rb