Skip to content

A ruby gem/engine to manage variables and feature flags

License

Notifications You must be signed in to change notification settings

coderhs/chitraguptan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Chitraguptan

Project Plan

Meaning: Hindu god/divine figure who is assigned with the task of record keeping

This is an app to develop the dynamic variable manager for Rails.

We save some values as constant in a rails model

class RfidTag < ActiveModel
  def self.filter_weak_rssi
    where('rssi < 100')
  end
end

Similarly we might code hard values at different parts of the app. To make this configurable we enter the values into the config file, env file, or store it in a model in the DB.

So they can be used as:

  where('rssi < ?', ENV['WEAK_RSSI'])
  # or
  where('rssi < ?', Rails.configuration.custom_config.weak_rssi)
  # or
  where('rssi < ?', RfidSetting.first.weak_rssi)

The first two of the above, requires re-deploying our rails app, and committing or changing files. The last one requires creating and maintaining an extra model. But it does allow one to change the variables on the file.

The aim of this project is to reduce the burden of managing variables. It is especially useful in building simple feature toggles.

  where('rssi < ?', Chitraguptan.get("week_rssi", default: 100))

Now this variable will be set as chitraguptan:week_rssi in your redis database and also stored in your database inside the table: chitraguptan_variables. The table has 3 fields namely, id, key and value (int 32, varchar and jsonb).

Current ADMIN UI

image

Installation

Disclaimer: Currently this project is in active development.

To install this gem add the following to your Gemfile.

gem 'chitraguptan', github: 'coderhs/chitraguptan'

then run bundle install

followed by

bundle exec rails generate chitraguptan:install

This will add an initializer file and admin url to your application routes.

The values you can control from initializer files are:

config.redis            = Redis.new # Provide connection string to your local or remote redis host
config.prefix           = 'chitraguptan' # We use the prefix to namespace the variables inserted and managed by the gem.
config.persist          = false # Persist flag will auto save all variables to your database, thus safeguarding it from a redis restart or crash
config.do_not_auto_load = true  # Auto load the existing value in the DB to redis on boot

If you are enabling the persist flag, you will need to add the migration to your rails app.

bundle exec rails generate chitraguptan:migrations

Purpose of this repo

Build the whole feature inside this repo and then extract it to a gem

Things to do

  1. Connect to redis - Done
  2. Configure to add prefix to the variables used - Done
  3. Define api to set data, delete data and give default if data doesn't exist - Done
  4. Load existing variables and set them in redis if they don't exist (during boot) - Done
  5. Admin UI to CRUD manage the variables - Done
  6. Extract the code to its own gem - Done
  7. Add to admin UI - Delete key
  8. Create gem install scripts - Done
    1. Create migration to persist data - Done
    2. Create initializer file - Done
    3. Add engine route to rails app routes
  9. Move get/set/delete/update to its own service classes
  10. Write test for whole code
  11. Control following settings from initializer
    1. Redis URL
    2. Auto persistance of variables - Done
    3. Auto load for variables during boot - Done
    4. Disable persistance in DB - Done
  12. Write more API documentation
  13. Release the gem to rubygems

Nice to have

  1. Load the list of variables from file (to use without the DB)

About

A ruby gem/engine to manage variables and feature flags

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published