Sha256: 90acf907b060189b266bb574f6fce3ecbe4203e684d8f15773b67cb95c669500

Contents?: true

Size: 650 Bytes

Versions: 19

Compression:

Stored size: 650 Bytes

Contents

require 'pp'
require 'rubygems'
require 'pathname'

root_path = Pathname(__FILE__).dirname.join('..').expand_path
lib_path  = root_path.join('lib')
$:.unshift(lib_path)

require 'toystore'

class NamespacedUUIDKeyFactory < Toy::Identity::AbstractKeyFactory
  def key_type
    String
  end

  def next_key(object)
    [object.class.name, SimpleUUID::UUID.new.to_guid].join(':')
  end
end

class User
  include Toy::Store
  key NamespacedUUIDKeyFactory.new
end

puts User.new.id # User:some_uuid

# or use namespaces for all classes

Toy.key_factory = NamespacedUUIDKeyFactory.new

class Game
  include Toy::Store
end

puts Game.new.id # Game:some_uuid

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
toystore-0.13.0 examples/namespacing_keys.rb
toystore-0.12.0 examples/namespacing_keys.rb
toystore-0.11.0 examples/namespacing_keys.rb
toystore-0.10.4 examples/namespacing_keys.rb
toystore-0.10.3 examples/namespacing_keys.rb
toystore-0.10.2 examples/namespacing_keys.rb
toystore-0.10.1 examples/namespacing_keys.rb
toystore-0.10.0 examples/namespacing_keys.rb
toystore-0.9.0 examples/namespacing_keys.rb
toystore-0.8.3 examples/namespacing_keys.rb
toystore-0.8.2 examples/namespacing_keys.rb
toystore-0.8.1 examples/namespacing_keys.rb
toystore-0.8.0 examples/namespacing_keys.rb
toystore-0.7.0 examples/namespacing_keys.rb
toystore-0.6.6 examples/namespacing_keys.rb
toystore-0.6.5 examples/namespacing_keys.rb
toystore-0.6.4 examples/namespacing_keys.rb
toystore-0.6.3 examples/namespacing_keys.rb
toystore-0.6.2 examples/namespacing_keys.rb