Project

toggleable

0.0
No commit activity in last 3 years
No release in over 3 years
Toggleable gem provides basic toggle functionality
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
>= 2.4.0
~> 10.0
~> 3.0
~> 3.0
>= 0.16.1

Runtime

 Project Readme

toggleable

CircleCI codecov Maintainability

Gem that provides toggle functionality.

Getting started

Install with:

$ gem install toggleable

You should initialize the toggleable first:

require "toggleable"

Toggleable.configure do |t|
  t.expiration_time = 3.minutes
end

You can pass the configurations for toggleable in the block above. Here is the configurable list:

  • use_memoization : set true to use memoization, so it doesn't hit your storage often. Default: false
  • expiration_time : Duration for memoization expiry. Default: 5 minutes
  • storage : Storage persistence to use, you should pass an object that responds to methods that specified in Toggleable::StorageAbstract class or use the provided implementation in toggleable/storage/*.rb. If not provided, it will use memory store as persistence. Default: Toggleable::MemoryStore
  • namespace : Prefix namespace for your stored keys. Default: toggleable
  • logger : Logger to use, you should pass an object that respond to methods that speciied in Toggleable::LoggerAbstract class. It will not log if none provided. Default: none

Usage

You could include Toggleable::Base to a class to provide toggling ability for that class.

class SampleFeature
  include Toggleable::Base

  DESC = 'this class can now be toggled'.freeze
end

SampleFeature.active?
# => 'false'

SampleFeature.activate!
# => "true"

# supply an actor for logging purposes
SampleFeature.deactivate! actor: user.id
# => 'false'

Managing Toggles

You could manage your toggles using Toggleable::FeatureToggler class.

# This will get all keys and its value
Toggleable::FeatureToggler.instance.available_features
# => {'key': 'true', 'other_key': 'false'}

Toggleable::FeatureToggler.mass_toggle!(mapping, actor: user.id)
# => 'true'

Redis Store Implementation

Redis implementation is also provided, you only need to pass your redis instance when configuring.

require 'redis'

redis = Redis.new

Toggleable.configure do |t|
  t.storage = Toggleable::RedisStore.new(redis)
end

Testing

This gem is tested against recent Ruby and ActiveSupport versions.

Contributor

BUKALAPAK TEAM

Contributing

Fork the project and send pull requests.