
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
FlexibleConfig promotes good OOP design, and the separation of logic and configuration in your Ruby classes.
FlexibleConfig allows you to set class constants cleanly in ruby with the heirarchical structure and clean workflow of YML config, without sacrificing the flexibility and immediacy of ENVironment variables.
module Bidding
class Calculator
FlexibleConfig.use 'auction.bidding' do |config|
BASE_RATE = config['base_rate']
TIME_DECAY = config['time_decay']
WIGGLE_ROOM = config['wiggle_room']
end
end
end
Or the more safer, (but more verbose) syntax:
module Bidding
class Calculator
FlexibleConfig.use 'auction.bidding' do |cfg|
BIDDING_ENABLED = cfg.fetch('enabled') { true }
BIDDER_EMAIL = cfg.to_s('email_from')
BASE_RATE = cfg.to_f('base_rate') { 1.0 }
TIME_DECAY = cfg.to_f('time_decay') { 3.0 }
ATTEMPTS = cfg.to_i('wiggle_room') { 2 }
end
end
end
config/settings/auction.yml
default:
base_rate: 1.0
time_decay: 3.0
wiggle_room: 0.2
development:
wiggle_room: 0.6
production:
wiggle_room: 0.2
AUCTION_BIDDING_BASE_RATE=1.0
AUCTION_BIDDING_TIME_DECAY=3.0
AUCTION_BIDDING_WIGGLE_ROOM=0.2
If your ENV variable is equal to the string 'true' or 'false' then
using the default #fetch
method on the config object will cast it to the
Ruby TrueClass
or FalseClass
automatically.
Casting to any Ruby type will work as long as the Ruby object and its string representation are safely interchangable:
example.yml
default:
safe: '123'
unsafe: '123oops'
FlexibleConfig.use 'example' do |cfg|
BASE_RATE = cfg.to_i('safe') # => 123
TIME_DECAY = cfg.to_i('unsafe') # => raises UnsafeConversion
end
Add this to the Rakefile
of your project:
# Load flexible config tasks
spec = Gem::Specification.find_by_name 'flexible-config'
load "#{spec.gem_dir}/lib/tasks/flexible_config.rake"
Type into the command line:
bundle exec rake flexible_config:print
If you'd like to become a contributor, the easiest way it to fork this repo, make your changes, run the specs and submit a pull request once they pass.
To run specs, run bundle install && bundle exec rspec
If your changes seem reasonable and the specs pass I'll give you commit rights to this repo and add you to the list of people who can push the gem.
Copyright (c) 2015 Grouper. See LICENSE for details.
FAQs
Unknown package
We found that flexible-config 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.