Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
rack-config-flexible
Advanced tools
A flexible configuration middleware for Rack that provides a simple DSL, as well as the ability to easily load configuration from yaml files.
This software is licensed under the Simplified BSD License as described in the LICENSE file.
gem install rack-config-flexible
Just add something like this to your config.ru:
require 'rack/config/flexible'
use Rack::Config::Flexible do
environment :production
section :data
set :key => 'value'
environment :development
section :data
set :key => 'dev_value'
# Set the current environment
environment :production
end
Of course, individual environments, sections, and even the entire configuration can be loaded from yaml files.
The configuration can be accessed by downstream middleware via the Rack environment. In the Usage example, you could access key's value as follows:
env['rack.config']['data.key']
and you can even modify values as follows:
env['rack.config']['data.key'] = 'new_value'
if, and only if, the given key exists. The format for the hash key is section.key.
require 'rack/config/flexible'
use Rack::Config::Flexible do
environment :production
section :data, 'cfg/production/data.yaml'
environment :development, 'cfg/development.yaml'
# Set the current environment
environment :production
end
Any calls to set after environment or section will override data loaded from the yaml file if the same key is specified. Otherwise, they'll just add the values to the hash per usual.
You can load the entire configuration from a single file, or a directory tree.
This example loads from a single file:
require 'rack/config/flexible'
use Rack::Config::Flexible :from_file => 'settings.yaml' do
# Set the current environment to production
environment :production
end
The settings.yaml file should be laid out like:
environment:
section:
key: value
So, the equivalent of the initial example would be:
production:
data:
key: value
development:
data:
key: dev_value
This example loads from a directory tree:
require 'rack/config/flexible'
use Rack::Config::Flexible :from_file => 'settings' do
# Set the current environment to production
environment :production
end
The directory tree is expected to be laid out like:
settings/environment/section.yaml
Where each directory under settings is an environment, containg a separate yaml file for each section. The yaml file itself will only hold key-value pairs for that particular section.
See the inline documentation for more details.
FAQs
Unknown package
We found that rack-config-flexible demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.