https://github.com/Volopay/configlogic.git
Configlogic is a simple configuration / settings solution that uses an ERB enabled YAML file. It has been based on github.com/settingslogic/settingslogic
gem 'configlogic', git: 'https://github.com/Volopay/configlogic.git' in your Gemfile
Create a class in lib initializer like (Please add ‘Vp` in the class name)
Rails.application.config.to_prepare do
class VpClientConfig < Configlogic
namespace Rails.env
cache_values_to_redis true
get_value_from_db true
config_class 'ClientConfig'
config_class_column :config #this has to be a json column
redis_key { Apartment::Tenant.current } # this has to be proc
source "#{Rails.root}/config/configsetting/client_config.yml" #This has to be very last call and mandatory
end
end
end
Few things to notice, source has to be last call. Options:
-
cache_values_to_redis : If you want to have cache the values, by default Rails.cache will be used
-
get_value_from_db : true If you want to store config values in DB, otherwise the json file supplied in source would be used
-
config_class : Class in which config json needs to be stored
-
config_class_column : Column of above class in which config json needs to be stored
-
redis_key : This needs to be a Proc, identifying a unique key prefix for keys, what gets saved in REDIS is something like this key ‘config-517aa5ee0eaef2d5c6b91d705de0bba1-modules.payments-enabled`
Using a namespace allows us to change our configuration depending on our environment: Make sure to have yml file name exactly same as initialize file name without Vp, in this example ‘client_config.yml` to `configsetting` folder `config/configsetting/client_config.yml`
defaults: &defaults
host: "volopay.com"
modules:
payments:
enabled: false
ocr:
UI: Rajesh Raikwar
billing:
data: something
enabled: true
column_value: "OCR"
international_payments:
enabled: true
bulk_payments:
enabled: true
cards:
enabled: true
card_request:
enabled: true
reimbursement:
enabled: true
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
Note: Certain Ruby/Bundler versions include a version of the Psych YAML parser which incorrectly handles merges (the ‘<<` in the example above.) If your default settings seem to be overwriting your environment-specific settings, including the following lines in your config/boot.rb file may solve the problem:
require 'yaml' YAML::ENGINE.yamler= 'syck'
>> Rails.env
=> "development"
>> VpConfig.get('host')
=> volopay.com
>> VpConfig.get('modules.payments.ocr.enabled')
=> "true"
Things to know if you try to access in between hash, it will throw `OperationNotAllowed` exception
=== 3. Access your settings
>> Rails.env
=> "development"
>> VpConfig.get('host')
=> volopay.com
>> VpConfig.get('modules.payments.ocr.enabled')
=> "true"
Things to know if you try to access in between hash, it will throw `OperationNotAllowed` exception
`rake configlogic:load` this gem also adds a rake task, which can be used to merge new settings the settings, whenever there are any changes in main config yml in code. it will basically loop all clients(if Apartment present, otherwise in public schema). and update the settings in all clients.
It adds a after commit hooks into the config_class provided that burset the cache variables as soon as there is a commit to config_class_column