Socket
Book a DemoInstallSign in
Socket

can-do

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-do

1.1.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

CanDo

Gem Version

Flips your features based on a redis key, a config/features.yml file or environment variables.

Usage

Add can-do to your Gemfile:

# Gemfile

gem "can-do", require: "can_do"

Redis values

To use redis as a storage set the environment variable CANDO_REDIS_URL with your redis instance.

The keys have to be prefixed with 'features:'.

So to set and use the feature experiment-1 set the key like

$ redis-cli SET features:experiment_1 true

and use it like

require "can_do"

CanDo.feature?(:experiment_1)

Any unset key will fall back to either the environment variable or the yaml variable and false if none is set.

require "can_do"

CanDo.feature?(:experiment_1)

Yaml File

Inside the config folder relative to your working directory create a file called features.yml. Within this file, place your default feature flags within the defaults key. All available features should be listed here, together with their default values. Add environment-specific feature flags under the environment name.

# config/features.yml

defaults:
  some_feature: false
  other_feature: true
development:
  some_feature: true
production:
  other_feature: false

Check if a feature is enabled by calling CanDo.feature?(:some_feature):

require "can_do"

CanDo.feature?(:some_feature)

Or by using a block:

require "can_do"

CanDo.feature?(:some_feature) do
  # This block is only evaluated if some_feature is enabled
end

If a feature is not found, false is returned.

Environment variables

You can use environment variables to flip your features. Environment variables always take precedence over anything within your config/features.yml file.

> RAILS_ENV=development rails console
CanDo.feature?(:some_feature) => false

> SOME_FEATURE=true RAILS_ENV=development rails console
CanDo.feature?(:some_feature) => true

> SOME_FEATURE=true RAILS_ENV=development rails console
CanDo.feature?(:some_feature) => true

> OTHER_FEATURE=true RAILS_ENV=production rails console
CanDo.feature?(:other_feature) => true

Contributing

  • Fork it ( https://github.com/blacklane/can-do/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

FAQs

Package last updated on 28 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.