Sha256: 2b4e69f618c1464266389c97c281fdd433e7a060d95a4bfb2625890fd5983d8e

Contents?: true

Size: 929 Bytes

Versions: 2

Compression:

Stored size: 929 Bytes

Contents

class Detour::Configuration
  attr_reader   :defined_groups
  attr_accessor :default_flaggable_class_name
  attr_accessor :flaggable_types
  attr_accessor :grep_dirs

  def initialize
    @defined_groups  = {}
    @flaggable_types = []
    @grep_dirs       = []
  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] = block
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
detour-0.0.3 lib/detour/configuration.rb
detour-0.0.2 lib/detour/configuration.rb