Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elcuervo/flag
Simple feature flags
https://github.com/elcuervo/flag
Last synced: 3 months ago
JSON representation
Simple feature flags
- Host: GitHub
- URL: https://github.com/elcuervo/flag
- Owner: elcuervo
- Created: 2014-04-23T22:17:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-01-14T14:43:12.000Z (almost 4 years ago)
- Last Synced: 2024-04-24T18:23:57.601Z (9 months ago)
- Language: Ruby
- Size: 23.4 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flag
[![Build Status](https://travis-ci.org/elcuervo/flag.svg?branch=master)](https://travis-ci.org/elcuervo/flag)Simple feature flags for any app
## Install
```
gem install flag
```## Initialize
`Flag` uses `Redic.new` if no other conenction is supplied
```ruby
Flag.store = Redic.new(ENV["OTHER_REDIS"]) # <3 Redic
```## Basic usage
```ruby
if Flag(:new_design).on?
# Shiny new design
else
# Marquee and blink everywhere
end
```If you enable (`on!`) with `Integer`, `Fixnum` or `String` they will be treated
as ids of your application, in the other hand if you use `Symbol` it will be
treated as a `Group`.```ruby
Flag(:something).on!(1)
Flag(:something).on!("uuid")Flag(:something).on!(:group)
```## Quiet mode
Sometimes you don't want to have your server down when doing flag checks:
```ruby
Flag.quiet!
# Now everything fails silentlyFlag.store = Redic.new("redis://localhost:5433/123")
Flag(:quack).on!
```## Enable/Check feature flags
### Ids
```ruby
Flag(:new_buttons).on! # Enabled for everyone
Flag(:new_buttons).off! # Disabled for everyoneFlag(:new_buttons).on!(1) # Enabled for id 1
Flag(:new_buttons).on?(1) #=> trueFlag(:new_buttons).on!("AnyRandomIdentification") # Use what you want as an id
Flag(:new_buttons).on?("AnyRandomIdentification") #=> true
```### Groups
```ruby
Flag.group[:staff] = lambda { |id| User.find(id).staff? }Flag(:new_scary_feature).on!(:staff) # This will run a block to check if it's valid
Flag(:new_scary_feature).on?(user.id) #=> true
```### Percentages
```ruby
Flag(:testing).on!("33%")
```## Info
```ruby
Flag.enabled # Shows you an array of the currently activated features
#=> [:landing_page]Flag.features # All the features, even the off ones
Flag.groups # The currently defined groups
#=> [:staff, :beta_testers]Flag(:holidays).activated # A hash with info on who has this feature active
#=> {:percentage => 100, :users => ["1"], :groups => [:staff] }
```