Sha256: b8c619e291e0d86c9c931acfe06bd523f0696ca7980e8a287c0a563ff105a1d1

Contents?: true

Size: 452 Bytes

Versions: 4

Compression:

Stored size: 452 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, *args)
    to_store(value, *args)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
toystore-0.7.0 lib/toy/identity/object_id_key_factory.rb
toystore-0.6.6 lib/toy/identity/object_id_key_factory.rb
toystore-0.6.5 lib/toy/identity/object_id_key_factory.rb
toystore-0.6.4 lib/toy/identity/object_id_key_factory.rb