Sha256: db1e944e5ea890ffca86b17186a9728dc906a7d767b840c01d600be4d457ceb0

Contents?: true

Size: 438 Bytes

Versions: 5

Compression:

Stored size: 438 Bytes

Contents

module Trax
  module Model
    class UUID < String
      def self.generate(prefix = nil)
        uuid = ::SecureRandom.uuid
        uuid[0..1] = prefix if prefix
        uuid
      end

      def record
        @record ||= record_type ? record_type.find_by(:"#{record_type.uuid_column}" => self) : nil
      end

      def record_type
        @record_type ||= ::Trax::Model::Registry.model_type_for_uuid(self)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trax_model-0.0.5 lib/trax/model/uuid.rb
trax_model-0.0.4 lib/trax/model/uuid.rb
trax_model-0.0.3 lib/trax/model/uuid.rb
trax_model-0.0.2 lib/trax/model/uuid.rb
trax_model-0.0.1 lib/trax/model/uuid.rb