<commit_before>[<img src="https://travis-ci.org/voormedia/flipflop.svg?branch=master" alt="Build Status">](https://travis-ci.org/voormedia/flipflop)

# Flipflop your features

**Flipflop** provides a declarative, layered way of enabling and disabling
application functionality at run-time. It is originally based on
[Flip](https://github.com/pda/flip). Compared to the original gem **Flipflop** has:
* an improved dashboard
* thread safety
* better database performance due to per-request caching, enabled by default
* more strategies (Redis, query strings, sessions, custom code)
* more strategy options (cookie options, strategy names and descriptions, custom database models)
* the ability to use the same strategy twice, with different options
* configuration in a fixed location (`config/features.rb`) that is usable even if you don't use the database strategy
* dashboard is inaccessible in production by default, for safety in case of misconfiguration
* removes controller filters and view helpers, to promote uniform semantics to check for features (facilitates project-wide searching)

You can configure strategy layers that will evaluate if a feature is currently
enabled or disabled. Available strategies are:
* a per-feature default setting
* database (with Active Record or Redis), to flipflop features site-wide for all users
* cookie or session, to flipflop features for single users
* query string parameters, to flipflop features occasionally (in development mode for example)
* custom strategy code

Flipflop has a dashboard interface that's easy to understand and use.

[<img src="https://raw.githubusercontent.com/voormedia/flipflop/screenshots/dashboard.png" alt="Dashboard">](https://raw.githubusercontent.com/voormedia/flipflop/screenshots/dashboard.png)

## Installation

Add the gem to your `Gemfile`:

```ruby
gem "flipflop"
```

Generate routes, feature settings and database migration:

```
rails g flipflop:install
```

Run the migration to store feature settings in your database:

```
rake db:migrate
```

## Declaring features

Features and strategies are declared in `config/features.rb`:

```ruby
Flipflop.configure do
  # Strategies will be used in the order listed here.
  strategy :cookie
  strategy :active_record
  strategy :default

  # Basic feature declaration:
  feature :shiny_things

  # Enable features by default:
  feature :world_domination, default: true
end
```

This file is automatically reloaded in development mode. No need to restart
your server after making changes.

## Strategies

The following strategies are provided:
* `:active_record` – Save feature settings in the database.
    * `:class` – Provide the feature model. `Flipflop::Feature` by default (which uses the table `features`). Honors `default_scope` when features are resolved or switched on/off.
* `:cookie` – Save feature settings in browser cookies for the current user.
    * `:prefix` – String prefix for all cookie names. Defaults to no prefix.
    * `:path` – The path for which the cookies apply. Defaults to the root of the application.
    * `:domain` – Cookie domain. Is `nil` by default (no specific domain). Can be `:all` to use the topmost domain. Can be an array of domains.
    * `:secure` – Only set cookies if the connection is secured with TLS. Default is `false`.
    * `:httponly` – Whether the cookies are accessible via scripting or only HTTP. Default is `false`.
* `:query_string` – Interpret query string parameters as features. This strategy is only used for resolving. It does not allow switching features on/off.
    * `:prefix` – String prefix for all query string parameters. Defaults to no prefix.
* `:redis` – Save feature settings in Redis.
    * `:client` – Use the specified Redis client instead of `Redis.new`.
    * `:prefix` – String prefix for all Redis keys. Defaults to no prefix.
* `:session` – Save feature settings in the current user's application session.
    * `:prefix` – String prefix for all session variables. Defaults to no prefix.
* `:default` – Not strictly needed, all feature defaults will be applied if no strategies match a feature. Include this strategy to determine the order of using the default value, and to make it appear in the dashboard.

All strategies support these options, to change the appearance of the dashboard:
* `:name` – The name of the strategy. Defaults to the name of the selected strategy.
* `:description` – The description of the strategy. Every strategy has a default description.
* `:hidden` – Optionally hides the strategy from the dashboard. Default is `false`.
<commit_msg>Add test strategy to strategies list.<commit_after>[<img src="https://travis-ci.org/voormedia/flipflop.svg?branch=master" alt="Build Status">](https://travis-ci.org/voormedia/flipflop)

# Flipflop your features

**Flipflop** provides a declarative, layered way of enabling and disabling
application functionality at run-time. It is originally based on
[Flip](https://github.com/pda/flip). Compared to the original gem **Flipflop** has:
* an improved dashboard
* thread safety
* better database performance due to per-request caching, enabled by default
* more strategies (Redis, query strings, sessions, custom code)
* more strategy options (cookie options, strategy names and descriptions, custom database models)
* the ability to use the same strategy twice, with different options
* configuration in a fixed location (`config/features.rb`) that is usable even if you don't use the database strategy
* dashboard is inaccessible in production by default, for safety in case of misconfiguration
* removes controller filters and view helpers, to promote uniform semantics to check for features (facilitates project-wide searching)

You can configure strategy layers that will evaluate if a feature is currently
enabled or disabled. Available strategies are:
* a per-feature default setting
* database (with Active Record or Redis), to flipflop features site-wide for all users
* cookie or session, to flipflop features for single users
* query string parameters, to flipflop features occasionally (in development mode for example)
* custom strategy code

Flipflop has a dashboard interface that's easy to understand and use.

[<img src="https://raw.githubusercontent.com/voormedia/flipflop/screenshots/dashboard.png" alt="Dashboard">](https://raw.githubusercontent.com/voormedia/flipflop/screenshots/dashboard.png)

## Installation

Add the gem to your `Gemfile`:

```ruby
gem "flipflop"
```

Generate routes, feature settings and database migration:

```
rails g flipflop:install
```

Run the migration to store feature settings in your database:

```
rake db:migrate
```

## Declaring features

Features and strategies are declared in `config/features.rb`:

```ruby
Flipflop.configure do
  # Strategies will be used in the order listed here.
  strategy :cookie
  strategy :active_record
  strategy :default

  # Basic feature declaration:
  feature :shiny_things

  # Enable features by default:
  feature :world_domination, default: true
end
```

This file is automatically reloaded in development mode. No need to restart
your server after making changes.

## Strategies

The following strategies are provided:
* `:active_record` – Save feature settings in the database.
    * `:class` – Provide the feature model. `Flipflop::Feature` by default (which uses the table `features`). Honors `default_scope` when features are resolved or switched on/off.
* `:cookie` – Save feature settings in browser cookies for the current user.
    * `:prefix` – String prefix for all cookie names. Defaults to no prefix.
    * `:path` – The path for which the cookies apply. Defaults to the root of the application.
    * `:domain` – Cookie domain. Is `nil` by default (no specific domain). Can be `:all` to use the topmost domain. Can be an array of domains.
    * `:secure` – Only set cookies if the connection is secured with TLS. Default is `false`.
    * `:httponly` – Whether the cookies are accessible via scripting or only HTTP. Default is `false`.
* `:query_string` – Interpret query string parameters as features. This strategy is only used for resolving. It does not allow switching features on/off.
    * `:prefix` – String prefix for all query string parameters. Defaults to no prefix.
* `:redis` – Save feature settings in Redis.
    * `:client` – Use the specified Redis client instead of `Redis.new`.
    * `:prefix` – String prefix for all Redis keys. Defaults to no prefix.
* `:session` – Save feature settings in the current user's application session.
    * `:prefix` – String prefix for all session variables. Defaults to no prefix.
* `:default` – Not strictly needed, all feature defaults will be applied if no strategies match a feature. Include this strategy to determine the order of using the default value, and to make it appear in the dashboard.
* `:test` – Simple strategy that stores features in memory. Useful for testing. If you call `Flipflop::FeatureSet.current.test!` this strategy is enabled and replaces all configured strategies.

All strategies support these options, to change the appearance of the dashboard:
* `:name` – The name of the strategy. Defaults to the name of the selected strategy.
* `:description` – The description of the strategy. Every strategy has a default description.
* `:hidden` – Optionally hides the strategy from the dashboard. Default is `false`.

The same strategy type can be used multiple times, as long as the options are
different. To prevent subtle bugs, an error is raised if two identical
strategies are configured.

{'fraction_non_alphanumeric': 0.07866931687415002, 'fraction_numerical': 0.0, 'mean_word_length': 4.620223398001176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6656891', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2440, 'n_words': 1258}