Sha256: 5abc06e47cee9fbcb426c1d12960c945db08985626bb80982d0533b7f7aef7eb
Contents?: true
Size: 872 Bytes
Versions: 2
Compression:
Stored size: 872 Bytes
Contents
module Toy module Identity extend ActiveSupport::Concern included do key Toy.key_factory end module ClassMethods def key(name_or_factory = :uuid) @key_factory = case name_or_factory when :uuid UUIDKeyFactory.new when :object_id require 'toy/identity/object_id_key_factory' ObjectIdKeyFactory.new else if name_or_factory.respond_to?(:next_key) && name_or_factory.respond_to?(:key_type) name_or_factory else raise InvalidKeyFactory.new(name_or_factory) end end attribute :id, @key_factory.key_type @key_factory end def next_key(object = nil) @key_factory.next_key(object).tap do |key| raise InvalidKey.new if key.nil? end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
toystore-0.6.3 | lib/toy/identity.rb |
toystore-0.6.2 | lib/toy/identity.rb |