Heimdall

Heimdall is a simple feature gate library that provides a mechanism to control access to features in your application. It uses a tree structure to represent feature flags and allows you to build and manage feature trees from templates. The library also includes access control checks to ensure that only authorized users can access certain features.

Features

  • Define and manage feature flags using a tree structure.
  • Build feature trees from JSON templates.
  • Perform access control checks based on feature flags.

Installation

Add this line to your application's Gemfile:

gem 'vp-heimdall'

And then execute:

bundle install

Usage

rails generate heimdall:install <NameOfClass> --prefix=[feature|feature_template] --type=[all|model|controller|migration] --path=<path of the controller> 

1) To install feature artifacts

```ruby
rails generate heimdall:install Feature --prefix=feature --type=all
```

2) To install feature Template artifacts

```ruby
rails generate heimdall:install FeatureTemplate --prefix=feature_template --type=all
```

3) add Heimdall in your application controller

```ruby
class ApplicationController < ActionController::API
  include Heimdall
end
```

Note: It is recommended to install templates in public schema if you are using multi-tenancy.

Some of the good practices

  1. keep feature name as snake_case and singular form. if a feature is sub-feature like google_login of user then it should be user.google_login. eg:

    feature_names:[`profile_enabled`, `user.security.google_login_enabled`]
    
  2. those features can we checked or accessed via

    Feature.
    
  3. if you want to check feature on controller. then you can create something like runes

    eg: we need to have UsersRune for UsersController

    if controller structure is considered to be this

        class UsersController < ApplicationController
          before_action only: [:google_login_link] do
            worthy? params[:action] #, UsersRune (optional rune class name if used unconventionally)
          end
    
          # some code
          def 
            # generate_login_url
          end
        end
    

    then rune structure should be

        class UsersRune 
          def 
            Feature.
          end
        end
    
  4. It can be directly used in serializer/jobs

  5. To maintain Singe Responsibility Principle, it is recommended to use runes for controllers and jobs. Try not to use in business logic like either in model or service functions.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/volopay/heimdall. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Heimdall project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.