You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Create a file with the features toggle definitions.
32
29
We suggest to name it as `featutes.yaml`, but it is up to you.
33
30
34
31
**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
32
36
-
```yaml
37
-
defaults:
38
-
new_payment_flow: false
39
-
rating_service: false
33
+
```yaml
34
+
defaults:
35
+
new_payment_flow: false
36
+
rating_service: false
40
37
41
-
development:
42
-
new_payment_flow: true
43
-
rating_service: false
38
+
development:
39
+
new_payment_flow: true
40
+
rating_service: false
44
41
45
-
your_environment:
46
-
new_payment_flow: true
47
-
```
42
+
your_environment:
43
+
new_payment_flow: true
44
+
```
48
45
49
46
3. Configure the environment and the path to the yaml.
50
47
51
-
```crystal
52
-
CanUse.configure do |config|
53
-
config.file = "path/to/features.yaml"
54
-
config.environment = "your_environment"
55
-
end
56
-
```
48
+
```crystal
49
+
CanUse.configure do |config|
50
+
config.file = "path/to/features.yaml"
51
+
config.environment = "your_environment"
52
+
end
53
+
```
57
54
58
55
4. Verify if a feature is toggled on/off
59
56
60
-
```crystal
61
-
if CanUse.feature?("new_payment_flow")
62
-
# do_something
63
-
end
64
-
```
57
+
```crystal
58
+
if CanUse.feature?("new_payment_flow")
59
+
# do_something
60
+
end
61
+
```
62
+
63
+
5. Enabling or Disabling a feature is simple as
64
+
65
+
> Enabling
66
+
67
+
```crystal
68
+
CanUse.feature?("feature_a") # => false
69
+
70
+
CanUse.enable("feature_a") # => true
71
+
72
+
CanUse.feature?("feature_a") # => true
73
+
```
74
+
75
+
> Disabling
76
+
77
+
```crystal
78
+
CanUse.feature?("feature_b") # => true
65
79
80
+
CanUse.disable("feature_b") # => false
81
+
82
+
CanUse.feature?("feature_b") # => false
83
+
```
66
84
67
85
## Development
68
86
69
87
1. Install the dependencies.
70
88
71
-
```bash
72
-
$ shards install
73
-
```
89
+
```bash
90
+
$ shards install
91
+
```
74
92
75
93
2. Implement and test your changes.
76
94
77
-
```bash
78
-
$ crystal spec
79
-
```
80
-
95
+
```bash
96
+
$ crystal spec
97
+
```
81
98
82
99
3. Run fomart tool to verify code style.
83
100
84
-
```bash
85
-
$ crystal tool format
86
-
```
101
+
```bash
102
+
$ crystal tool format
103
+
```
87
104
88
105
## TODO
89
106
90
-
- [ ] Add ability to toggle on/off a feature programatically, ex: `CanUse.enable("feature")`.
91
107
- [ ] Allows ENVIRONMENT variables to set/override a value for a key.
92
108
93
109
## Contributing
@@ -98,12 +114,10 @@ We suggest to name it as `featutes.yaml`, but it is up to you.
98
114
4. Push to the branch (`git push origin my-new-feature`)
99
115
5. Create a new Pull Request
100
116
101
-
## Credits
102
-
103
-
This shard was initially inspired by [can_do][1] (Ruby).
104
-
105
117
## Contributors
106
118
107
119
- [Rodrigo Pinto](https://github.com/rodrigopinto) - creator and maintainer
108
120
109
-
[1]: https://github.com/blacklane/can_do
121
+
## Credits
122
+
123
+
This shard was initially inspired by [can_do](https://github.com/blacklane/can_do).
0 commit comments