can_use
🤔Can I use this feature? Hmm, let me see.
CanUse is a minimalist feature toggle/flag for crystal, based on yaml file.
Installation
- Add the dependency to your shard.yml:
dependencies:
  can_use:
    github: rodrigopinto/can_use- Run shards install
Usage
- Require the library on your code base.
require "can_use"- 
Create a file with the features toggle definitions. We suggest to name it as featutes.yaml, but it is up to you.Note: The defaultsblock is mandatory, as it will be used as fallback when values are not defined on the environment set onconfiguration. Example:
defaults:
  new_payment_flow: false
  rating_service: false
development:
  new_payment_flow: true
  rating_service: false
your_environment:
  new_payment_flow: true- Configure the environment and the path to the yaml.
CanUse.configure do |config|
  config.file = "path/to/features.yaml"
  config.environment = "your_environment"
end- Verify if a feature is toggled on/off
if CanUse.feature?("new_payment_flow")
  # do_something
end- Enabling or Disabling a feature is simple as
Enabling
CanUse.feature?("feature_a") # => false
CanUse.enable("feature_a") # => true
CanUse.feature?("feature_a") # => trueDisabling
CanUse.feature?("feature_b") # => true
CanUse.disable("feature_b") # => false
CanUse.feature?("feature_b") # => falseDevelopment
- Install the dependencies.
$ shards install- Implement and test your changes.
$ crystal spec- Run fomart tool to verify code style.
$ crystal tool formatTODO
- [ ] Allows ENVIRONMENT variables to set/override a value for a key.
Contributing
- Fork it (https://github.com/rodrigopinto/can_use/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
- Rodrigo Pinto - creator and maintainer
Credits
This shard was initially inspired by can_do.