Sha256: 5144adcce85d3ff4c8f482720f3d39a8e75085d9318119b4a4da4502c05614a3

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

class Detour::Configuration
  attr_reader   :defined_groups
  attr_reader   :feature_search_regex
  attr_accessor :flaggable_types
  attr_accessor :feature_search_dirs

  def initialize
    @defined_groups      = {}
    @flaggable_types     = []
    @feature_search_dirs = []
  end

  # Defines the regular expression used to search for features. It must include
  # a single match group.
  #
  # @example
  #   Detour.config.feature_search_regex = /\.rollout\? :(\w+)/
  #
  # @param [Regexp] regex A regex to use to search for feature checks with.
  def feature_search_regex=(regex)
    if regex.is_a? Regexp
      @feature_search_regex = regex
    else
      raise "Feature search regex must be an instance of Regexp"
    end
  end

  # Allows for methods of the form `define_user_group` that call the private
  # method `define_group_for_class`. A new group for any `User` records will
  # be created that rollouts can be attached to.
  #
  # @example
  #   Detour.config.define_user_group :admins do |user|
  #     user.admin?
  #   end
  def method_missing(method, *args, &block)
    if /^define_(?<klass>[a-z0-9_]+)_group/ =~ method
      define_group_for_class(klass.classify, args[0], &block)
    else
      super
    end
  end

  private

  def define_group_for_class(klass, group_name, &block)
    @defined_groups[klass] ||= {}
    @defined_groups[klass][group_name] = Detour::DefinedGroup.new(group_name, block)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
detour-0.0.15 lib/detour/configuration.rb
detour-0.0.14 lib/detour/configuration.rb
detour-0.0.13 lib/detour/configuration.rb
detour-0.0.12 lib/detour/configuration.rb
detour-0.0.11 lib/detour/configuration.rb
detour-0.0.10 lib/detour/configuration.rb
detour-0.0.9 lib/detour/configuration.rb