Complexity Score
Low
Open Issues
0
Dependent Projects
51
Weekly Downloadsglobal
100
Keywords
License
- MIT
- Yesattribution
- Permissivelinking
- Permissivedistribution
- Permissivemodification
- Nopatent grant
- Yesprivate use
- Permissivesublicensing
- Notrademark grant
Downloads
Readme
GemConfig
A nifty way to make your gem configurable.
Usage
As a gem author
Include the gem and add configuration options like this:
# awesomeness.gemspec
Gem::Specification.new do |gem|
...
gem.add_runtime_dependency 'gem_config'
end
# lib/awesomeness.rb
require 'gem_config'
module Awesomeness
include GemConfig::Base
with_configuration do
has :api_key, classes: String
has :format, values: [:json, :xml], default: :json
has :region, values: ['us-west', 'us-east', 'eu'], default: 'us-west'
end
end
Access the configuration values in the gem’s code like this:
Awesomeness.configuration.api_key # Whatever the user set
To execute something after the gem is configured:
module Awesomeness
include GemConfig::Base
# ...
after_configuration_change do
# configure some other gem you're using, perhaps
end
end
As a gem user
Include and configure a gem like this:
# Gemfile
gem 'awesomeness'
# config/initializers/awesomeness.rb
Awesomeness.configure do |config|
config.api_key = 'foobarbaz'
config.format = :xml
config.region = 'eu'
end
# or
Awesomeness.configuration.api_key = 'foobarbaz'
Of course configuration values are checked against the allowed classes
and values
, and the default
is used if no value is provided.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Support
If you like this project, consider buying me a coffee! :)
Dependencies
No runtime dependency information found for this package.
CVE IssuesActive
0
Scorecards Score
3.00
Test Coverage
No Data
Follows Semver
Yes
Github Stars
75
Dependenciestotal
3
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No
Learn how to distribute gem_config in your own private RubyGems registry
10 Releases
RubyGems on Cloudsmith