Sha256: 2a7eec703362e6d374e23143c0dc4694c3ba4c0d7111bfb02dfab9df86426d7c
Contents?: true
Size: 685 Bytes
Versions: 2
Compression:
Stored size: 685 Bytes
Contents
module Flipper class Registry class Error < StandardError; end class DuplicateKey < Error; end class MissingKey < Error; end def initialize(source = {}) @mutex = Mutex.new @source = source end def add(key, value) @mutex.synchronize do if @source[key] raise DuplicateKey, "#{key} is already registered" else @source[key] = value end end end def get(key) @mutex.synchronize do @source[key] end end def each(&block) @mutex.synchronize { @source.dup }.each(&block) end def clear @mutex.synchronize { @source.clear } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
flipper-0.1.1 | lib/flipper/registry.rb |
flipper-0.1.0 | lib/flipper/registry.rb |