<commit_before>[![Build Status](https://api.travis-ci.org/tdumitrescu/feature_guard.png)](https://travis-ci.org/tdumitrescu/feature_guard)

# FeatureGuard

Lightweight Redis-based feature-flagging for Ruby apps. Provides a simple syntax for enabling and disabling features, or gradually ramping up and down by enabling features for a percentage of total traffic.

## Installation

Add this line to your application's Gemfile:

    gem 'feature_guard'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install feature_guard

## Usage

Check whether a feature is enabled globally:

```ruby
FeatureGuard.enabled? :my_feature
```

Globally enable or disable a feature:

```ruby
FeatureGuard.enable  :my_feature
FeatureGuard.disable :my_feature
FeatureGuard.toggle  :my_feature
```

Feature names can be strings or symbols. No data setup is necessary; any check for a feature which has never been enabled simply returns false.

For more fine-grained control, set a ramp-up value to decide which percentage of traffic should see the feature:

```ruby
FeatureGuard.set_ramp  :my_feature, 30.5  # 30.5%
FeatureGuard.bump_ramp :my_feature, 12    # 30.5 + 12 = 42.5%
FeatureGuard.bump_ramp :my_feature        # 42.5 + 10 = 52.5%

FeatureGuard.ramp_val :my_feature # 52.5
```

`.set_ramp` sets the ramp-up value; `.bump_ramp` increments or decrements it by a given value (defaults to 10.0). Check the current ramp-up value with `.ramp_val`.

Check whether to show the feature at the current ramp-up value:

```ruby
FeatureGuard.allow? :my_feature, user_id
# true for 52.5% of user_id values

FeatureGuard.allow? :my_feature
# true for 52.5% of checks (random)
```

The optional second argument to`.allow?` can be of any type (e.g., user ID or name or even an object). It is hashed with the feature name to create a reproducible numeric value for checking whether to return true or false based on the current ramp-up value. With no second argument, `.allow?` uses a new random value on every call.

To retrieve information on all binary-enabled/disabled features, use `.all_flags`:

```ruby
FeatureGuard.enable :my_feature
FeatureGuard.enable :another_feature
FeatureGuard.toggle :my_feature
FeatureGuard.all_flags
# {"my_feature"=>"0", "another_feature"=>"1"}
```

To retrieve information on all ramp values, use `.all_ramps`:

```ruby
FeatureGuard.set_ramp :my_feature, 50
FeatureGuard.set_ramp :another_feature, 30
FeatureGuard.all_ramps
# {"my_feature"=>"50.0", "another_feature"=>"30.0"}
```

## Configuration

Optionally change the Redis client with:

```ruby
FeatureGuard.redis = my_redis_client
```

Setting `FeatureGuard.redis` to `nil` will revert it to a new default instance (`Redis.new`).
<commit_msg>update README with new return vals for .all methods<commit_after>[![Build Status](https://api.travis-ci.org/tdumitrescu/feature_guard.png)](https://travis-ci.org/tdumitrescu/feature_guard)

# FeatureGuard

Lightweight Redis-based feature-flagging for Ruby apps. Provides a simple syntax for enabling and disabling features, or gradually ramping up and down by enabling features for a percentage of total traffic.

## Installation

Add this line to your application's Gemfile:

    gem 'feature_guard'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install feature_guard

## Usage

Check whether a feature is enabled globally:

```ruby
FeatureGuard.enabled? :my_feature
```

Globally enable or disable a feature:

```ruby
FeatureGuard.enable  :my_feature
FeatureGuard.disable :my_feature
FeatureGuard.toggle  :my_feature
```

Feature names can be strings or symbols. No data setup is necessary; any check for a feature which has never been enabled simply returns false.

For more fine-grained control, set a ramp-up value to decide which percentage of traffic should see the feature:

```ruby
FeatureGuard.set_ramp  :my_feature, 30.5  # 30.5%
FeatureGuard.bump_ramp :my_feature, 12    # 30.5 + 12 = 42.5%
FeatureGuard.bump_ramp :my_feature        # 42.5 + 10 = 52.5%

FeatureGuard.ramp_val :my_feature # 52.5
```

`.set_ramp` sets the ramp-up value; `.bump_ramp` increments or decrements it by a given value (defaults to 10.0). Check the current ramp-up value with `.ramp_val`.

Check whether to show the feature at the current ramp-up value:

```ruby
FeatureGuard.allow? :my_feature, user_id
# true for 52.5% of user_id values

FeatureGuard.allow? :my_feature
# true for 52.5% of checks (random)
```

The optional second argument to`.allow?` can be of any type (e.g., user ID or name or even an object). It is hashed with the feature name to create a reproducible numeric value for checking whether to return true or false based on the current ramp-up value. With no second argument, `.allow?` uses a new random value on every call.

To retrieve information on all binary-enabled/disabled features, use `.all_flags`:

```ruby
FeatureGuard.enable :my_feature
FeatureGuard.enable :another_feature
FeatureGuard.toggle :my_feature
FeatureGuard.all_flags
# {"my_feature"=>false, "another_feature"=>true}
```

To retrieve information on all ramp values, use `.all_ramps`:

```ruby
FeatureGuard.set_ramp :my_feature, 50
FeatureGuard.set_ramp :another_feature, 30
FeatureGuard.all_ramps
# {"my_feature"=>50.0, "another_feature"=>30.0}
```

## Configuration

Optionally change the Redis client with:

```ruby
FeatureGuard.redis = my_redis_client
```

Setting `FeatureGuard.redis` to `nil` will revert it to a new default instance (`Redis.new`).

{'fraction_non_alphanumeric': 0.094257064721969, 'fraction_numerical': 0.017137648131267093, 'mean_word_length': 4.750524109014675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '1580943', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1653, 'n_words': 636}