Feature is a feature toggle library for ruby.
The feature toggle functionality has to be configured by feature repositories. A feature repository simply provides lists of active and inctive features. With this approach Feature is higly configurable and not bound to a specific kind of configuration.
gem install feature
require 'feature'
repo = Feature::Repository::SimpleRepository.new
repo.add_active_feature :be_nice
Feature.set_repository repo
Feature.active?(:be_nice)
# => true
Feature.with(:be_nice) do
puts "you can read this"
end
# File: Gemfile
gem 'feature' # Or with version specifier, e.g. '~> 0.4.0'
# File: config/feature.yml
features:
an_active_feature: true
an_inactive_feature: false
# File: config/initializers/feature.rb
repo = Feature::Repository::YamlRepository.new("#{Rails.root}/config/feature.yml")
Feature.set_repository repo
# File: app/views/example/index.html.erb
<% if Feature.active?(:an_active_feature) %>
<%# Feature implementation goes here %>
<% end %>
