A Rails engine to turn on/off features (Feature flipper).
- Manage features with notices
- Manage site notices with themes
- Rails version 5 and above
- MySQL
Add this line to your application's Gemfile:
gem 'plug'Execute:
β bundleAnd run the install generator:
β rails g plug:install
β rails plug:install:migrations
β rails db:migrate
β rails sGo to localhost:3000/plug and start creating features.
Use the provided method to check if the feature is enabled.
Plug.enabled?('my-awesome-feature-slug')If you wanted to restrict routes, you can use Plug::Constraint class
Rails.application.routes.draw do
resources :blog, constraint: Plug::Constraint.new('my-awesome-feature-slug')
endNotices can be displayed using the Plug.notice method.
<%= Plug.notice('my-awesome-feature-slug') %>If you have custom HTML for notice, you can pass a block.
<% Plug.notice('my-awesome-feature-slug') do |notice| %>
<div class="alert">
<p><%= notice %></p>
</div>
<% end %>Add buttons to the config block to perform rake tasks from the plug dashboard
config.buttons = [
{ label: 'Clear cache', task: 'tmp:cache:clear' }
]Themes can be added in Site Notices. Themes are just string stored in the database. You still need to style the theme.
By default, we have default and dark in config/plug.rb. Below is an example on how you can utilise the theme string.
- theme_class = "site-notice--#{site_notice.theme}"
.site-notice{ class: theme_class }
%p My site notice// BEM
.site-notice {
@include modifier('default') {
...
}
@include modifier('dark') {
...
}
}β rails g migration MyAwesomeMigration
β rails g model MyModel name:string slug:string:index
β rails db:migrate
β rails db:migrate RAILS_ENV=test
β rake plug:install:migrations # Run this on the app to copy the new migrationsβ bundle exec rspec specMake sure to bump the version. Rubygems don't accept version overrides.
β gem build plug.gemspec
β gem push plug-<version>.gemMake sure to match the version with the Rubygems version.
β npm login
β npm publish --access public- Ability to disable all features using one button
- Add screenshot
- Allow block parameters for
enabled?method - Versioning of features
- History of feature activities
File a new issue if you have questions or issues.
- Fork it ( https://github.com/boost/digitalnz/fork )
- Create your feature branch (
git checkout -b my-awesome-feature) - Commit your changes (
git commit -am 'Add my awesome feature!') - Push to the branch (
git push origin my-awesome-feature) - Create a new Pull Request