Flag

Build Status

Simple feature flags for any app

Install

gem install flag

Initialize

Flag uses Redic.new if no other conenction is supplied

Flag.store = Redic.new(ENV["OTHER_REDIS"]) # <3 Redic

Basic usage

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.

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:

Flag.quiet!
# Now everything fails silently

Flag.store = Redic.new("redis://localhost:5433/123")
Flag(:quack).on!

Enable/Check feature flags

Ids

Flag(:new_buttons).on!  # Enabled for everyone
Flag(:new_buttons).off! # Disabled for everyone

Flag(:new_buttons).on!(1) # Enabled for id 1
Flag(:new_buttons).on?(1) #=> true

Flag(:new_buttons).on!("AnyRandomIdentification") # Use what you want as an id
Flag(:new_buttons).on?("AnyRandomIdentification") #=> true

Groups

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

Flag(:testing).on!("33%")

Info

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] }