Flag

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

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