Sha256: 29030696f799fe4cbeab6ae38a36bd64496b3cd33e55a25d1c592a7559097cc1

Contents?: true

Size: 431 Bytes

Versions: 2

Compression:

Stored size: 431 Bytes

Contents

require 'bson'

module Toy
  module Identity
    class ObjectIdKeyFactory < AbstractKeyFactory
      def key_type
        BSON::ObjectId
      end

      def next_key(object)
        BSON::ObjectId.new
      end
    end
  end
end

class BSON::ObjectId
  def self.to_store(value, *)
    return value if value.is_a?(BSON::ObjectId)
    BSON::ObjectId.from_string(value.to_s)
  end

  def self.from_store(value, *)
    value
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
toystore-0.6.3 lib/toy/identity/object_id_key_factory.rb
toystore-0.6.2 lib/toy/identity/object_id_key_factory.rb