|
| 1 | +# can_use |
| 2 | + |
| 3 | +🤔 Can I use this feature? Yes, sure! |
| 4 | + |
| 5 | +> CanUse is a minimalist feature toggle/flag for crystal, based on yaml file. |
| 6 | +
|
| 7 | +[](https://github.com/rodrigopinto/can_use/releases) |
| 8 | + |
| 9 | +[](https://travis-ci.org/rodrigopinto/can_use) |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +1. Add the dependency to your `shard.yml`: |
| 14 | + |
| 15 | +```yaml |
| 16 | +dependencies: |
| 17 | + can_use: |
| 18 | + github: rodrigopinto/can_use |
| 19 | +``` |
| 20 | +2. Run `shards install` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | + |
| 25 | +1. Require the library on your code base. |
| 26 | + |
| 27 | + ```crystal |
| 28 | + require "can_use" |
| 29 | + ``` |
| 30 | + |
| 31 | +2. Create a file with the features toggle definitions. |
| 32 | +We suggest to name it as `featutes.yaml`, but it is up to you. |
| 33 | + |
| 34 | + **Note:** The `defaults` block is mandatory, as it will be used as fallback when values are not defined on the environment set on `configuration`. Example: |
| 35 | + |
| 36 | + ```yaml |
| 37 | + defaults: |
| 38 | + new_payment_flow: false |
| 39 | + rating_service: false |
| 40 | +
|
| 41 | + development: |
| 42 | + new_payment_flow: true |
| 43 | + rating_service: false |
| 44 | +
|
| 45 | + your_environment: |
| 46 | + new_payment_flow: true |
| 47 | + ``` |
| 48 | + |
| 49 | +3. Configure the environment and the path to the yaml. |
| 50 | + |
| 51 | + ```crystal |
| 52 | + CanUse.configure do |config| |
| 53 | + config.file = "path/to/features.yaml" |
| 54 | + config.environment = "your_environment" |
| 55 | + end |
| 56 | + ``` |
| 57 | + |
| 58 | +4. Verify if a feature is toggled on/off |
| 59 | + |
| 60 | + ```crystal |
| 61 | + if CanUse.feature?("new_payment_flow") |
| 62 | + # do_something |
| 63 | + end |
| 64 | + ``` |
| 65 | + |
| 66 | + |
| 67 | +## Development |
| 68 | + |
| 69 | +1. Install the dependencies. |
| 70 | + |
| 71 | + ```bash |
| 72 | + $ shards install |
| 73 | + ``` |
| 74 | + |
| 75 | +2. Implement and test your changes. |
| 76 | + |
| 77 | + ```bash |
| 78 | + $ crystal spec |
| 79 | + ``` |
| 80 | + |
| 81 | + |
| 82 | +3. Run fomart tool to verify code style. |
| 83 | + |
| 84 | + ```bash |
| 85 | + $ crystal tool format |
| 86 | + ``` |
| 87 | + |
| 88 | +## TODO |
| 89 | + |
| 90 | +- [ ] Add ability to toggle on/off a feature programatically, ex: `CanUse.enable("feature")`. |
| 91 | +- [ ] Allows ENVIRONMENT variables to set/override a value for a key. |
| 92 | + |
| 93 | +## Contributing |
| 94 | + |
| 95 | +1. Fork it (<https://github.com/rodrigopinto/can_use/fork>) |
| 96 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 97 | +3. Commit your changes (`git commit -am 'Add some feature'`) |
| 98 | +4. Push to the branch (`git push origin my-new-feature`) |
| 99 | +5. Create a new Pull Request |
| 100 | + |
| 101 | +## Credits |
| 102 | + |
| 103 | +This shard was initially inspired by [can_do][1] (Ruby). |
| 104 | + |
| 105 | +## Contributors |
| 106 | + |
| 107 | +- [Rodrigo Pinto](https://github.com/rodrigopinto) - creator and maintainer |
| 108 | + |
| 109 | +[1]: https://github.com/blacklane/can_do |
0 commit comments