Module Feature
In: lib/feature/repository.rb
lib/feature/generators/install_generator.rb
lib/feature/testing.rb
lib/feature/repository/yaml_repository.rb
lib/feature/repository/redis_repository.rb
lib/feature/repository/simple_repository.rb
lib/feature/repository/active_record_repository.rb
lib/feature.rb

Feature module provides all methods

  • to set a feature repository
  • to check if a feature (represented by a symbol) is active or inactive
  • for conditional block execution with or without a feature
  • to refresh the feature lists (request them from repository)

@note all features not active will be handled has inactive

Example usage:

  repository = SimpleRepository.new
  repository.add_active_feature(:feature_name)

  Feature.set_repository(repository)
  Feature.active?(:feature_name)
  # => true
  Feature.inactive?(:inactive_feature)
  # => false

  Feature.with(:feature_name) do
    # code will be executed
  end

Methods

Classes and Modules

Module Feature::Repository
Class Feature::InstallGenerator

Public Class methods

Requests if feature is active

@param [Symbol] feature @return [Boolean]

Return list of active feature flags.

@return [Array] list of symbols

Requests if feature is inactive (or unknown)

@param [Symbol] feature @return [Boolean]

Refreshes list of active features from repository. Useful when using an repository with external source.

Execute the code block with the given features active

Example usage:

  Feature.run_with_activated(:feature, :another_feature) do
    # your test code here
  end

Execute the code block with the given features deactive

Example usage:

  Feature.run_with_deactivated(:feature, :another_feature) do
    # your test code here
  end

Set the feature repository The given repository has to respond to method ‘active_featureswith an array of symbols

@param [Object] repository the repository to get the features from @param [Boolean|Integer] refresh optional (default: false) - auto refresh or refresh after given number of seconds

Return value or execute Proc/lambda depending on Feature status.

@param [Symbol] feature @param [Object] value / lambda to use if feature is active @param [Object] value / lambda to use if feature is inactive

Execute the given block if feature is active

@param [Symbol] feature

Execute the given code block and store + restore the feature configuration before/after the execution

Execute the given block if feature is inactive

@param [Symbol] feature

[Validate]