toggle
Version, currently 0.1.0-pre2 versions
- 0.1.1latestAug 26, 2021
- 0.1.0-prenot indexedJan 2, 2022
github.com/lucasintel/toggle.cr
Feature toggles for Crystal
Nothing has been indexed for 0.1.0-pre yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
toggle:
github: lucasintel/toggle.cr
version: ~> 0.1.0-preThen run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0-pre. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
Toggle
Toggle is a small feature toggle library for Crystal.
References
- Feature Toggles (Martin Fowler)
- Using Feature Flags to Ship Changes with Confidence (Travis CI)
- Feature flags in the development of GitLab (Gitlab)
Installation
-
Add the dependency to your
shard.yml:dependencies: toggle: github: kandayo/toggle.cr -
Run
shards install
Usage
Getting Started
Use Toggle#init to initialize a global, easy-to-use default instance.
require "toggle"
require "toggle/backend/redis"
redis = Redis::PooledClient.new
backend = Toggle::Backend::Redis.new(redis: redis, keyspace: "_app_toggles")
Toggle.init(backend: backend)
Toggle.enable("payment_methods::pix")
Toggle.enabled?("payment_methods::pix") # => true
You can also instantiate multiple instances. Useful for managing features in large applications.
require "toggle"
require "toggle/backend/redis"
redis = Redis::PooledClient.new
tenant1_backend = Toggle::Backend::Redis.new(redis: redis, keyspace: "_tenant1_toggles")
tenant1 = Toggle::Instance.new(backend: tenant1_backend)
tenant2_backend = Toggle::Backend::Redis.new(redis: redis, keyspace: "_tenant2_toggles")
tenant2 = Toggle::Instance.new(backend: tenant2_backend)
# Enable "store::async_checkout" only for Tenant 1.
tenant1.enable("store::new_checkout")
tenant1.enabled?("store::new_checkout") # => true
tenant2.enabled?("store::new_checkout") # => false
Backend
Redis Backend
require "redis"
require "toggle"
require "toggle/backend/redis"
backend = Toggle::Backend::Redis.new(redis: redis, keyspace: "_tenant1_toggles")
Features are stored in a HASH on Redis.
In Memory Backend
require "toggle"
require "toggle/backend/memory"
backend = Toggle::Backend::Memory.new
Features are stored in memory.
Custom Backend
You can create your own backend using the Toggle::Backend::Base interface.
Contributing
- Fork it (https://github.com/kandayo/togglecr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- kandayo - creator and maintainer
License
The lib is available as open source under the terms of the MIT License.
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0-pre- Tagged
- Jan 2, 2022
- Commit
b8433efeefa0- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/lucasintel/toggle.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 2