Sha256: 05227c7d919226efe22d9d31eb9379ca119bac61cbd873b1b186e6f214fc442c

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

module Flipper
  # Private: The namespace for all instrumented events.
  InstrumentationNamespace = :flipper

  # Public: Start here. Given an adapter returns a handy DSL to all the flipper
  # goodness. To see supported options, check out dsl.rb.
  def self.new(adapter, options = {})
    DSL.new(adapter, options)
  end

  # Public: Use this to register a group by name.
  #
  # name - The Symbol name of the group.
  # block - The block that should be used to determine if the group matches a
  #         given thing.
  #
  # Examples
  #
  #   Flipper.register(:admins) { |thing|
  #     thing.respond_to?(:admin?) && thing.admin?
  #   }
  #
  # Returns a Flipper::Group.
  # Raises Flipper::DuplicateGroup if the group is already registered.
  def self.register(name, &block)
    group = Types::Group.new(name, &block)
    groups.add(group.name, group)
    group
  rescue Registry::DuplicateKey
    raise DuplicateGroup, %Q{Group #{name.inspect} has already been registered}
  end

  # Public: Clears the group registry.
  #
  # Returns nothing.
  def self.unregister_groups
    groups.clear
  end

  # Public: Check if a group exists
  #
  # Returns boolean
  def self.group_exists?(name)
    self.groups.key?(name)
  end

  # Internal: Fetches a group by name.
  #
  # name - The Symbol name of the group.
  #
  # Examples
  #
  #   Flipper.group(:admins)
  #
  # Returns the Flipper::Group if group registered.
  # Raises Flipper::GroupNotRegistered if group is not registered.
  def self.group(name)
    groups.get(name)
  rescue Flipper::Registry::KeyNotFound => e
    raise GroupNotRegistered, "Group #{e.key.inspect} has not been registered"
  end

  # Internal: Registry of all groups.
  def self.groups
    @groups ||= Registry.new
  end

  # Internal: Change the groups registry.
  def self.groups=(registry)
    @groups = registry
  end
end

require 'flipper/adapter'
require 'flipper/dsl'
require 'flipper/errors'
require 'flipper/feature'
require 'flipper/gate'
require 'flipper/registry'
require 'flipper/type'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-0.6.3 lib/flipper.rb
flipper-0.6.2 lib/flipper.rb