Sha256: 04244c583dcbcdb57fa553ced6c0639e69b7230c5cea18330aceb4c42ac445a7

Contents?: true

Size: 506 Bytes

Versions: 1

Compression:

Stored size: 506 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
        else
          name_or_factory
        end
      end

      def next_key(object = nil)
        @key_factory.next_key(object).tap do |key|
          raise "Keys may not be nil" if key.nil?
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toystore-0.5 lib/toy/identity.rb