class Flipper::Registry

Internal: Used to store registry of groups by name.

Public Class Methods

new(source = {}) click to toggle source
# File lib/flipper/registry.rb, line 21
def initialize(source = {})
  @mutex = Mutex.new
  @source = source
end

Public Instance Methods

add(key, value) click to toggle source
# File lib/flipper/registry.rb, line 34
def add(key, value)
  key = key.to_sym

  @mutex.synchronize do
    if @source[key]
      raise DuplicateKey, "#{key} is already registered"
    else
      @source[key] = value
    end
  end
end
clear() click to toggle source
# File lib/flipper/registry.rb, line 64
def clear
  @mutex.synchronize { @source.clear }
end
each(&block) click to toggle source
# File lib/flipper/registry.rb, line 60
def each(&block)
  @mutex.synchronize { @source.dup }.each(&block)
end
get(key) click to toggle source
# File lib/flipper/registry.rb, line 46
def get(key)
  key = key.to_sym
  @mutex.synchronize do
    @source[key]
  end
end
key?(key) click to toggle source
# File lib/flipper/registry.rb, line 53
def key?(key)
  key = key.to_sym
  @mutex.synchronize do
    @source.key?(key)
  end
end
keys() click to toggle source
# File lib/flipper/registry.rb, line 26
def keys
  @mutex.synchronize { @source.keys }
end
values() click to toggle source
# File lib/flipper/registry.rb, line 30
def values
  @mutex.synchronize { @source.values }
end