{"id":13763738,"url":"https://github.com/dasch/king_konf","last_synced_at":"2025-06-14T01:40:38.745Z","repository":{"id":25240995,"uuid":"103527493","full_name":"dasch/king_konf","owner":"dasch","description":"Simple configuration library that works well with ENV vars and config files","archived":false,"fork":false,"pushed_at":"2022-10-03T12:35:47.000Z","size":83,"stargazers_count":23,"open_issues_count":3,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-23T01:23:53.098Z","etag":null,"topics":["configuration","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dasch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-14T12:06:52.000Z","updated_at":"2024-10-15T02:01:46.000Z","dependencies_parsed_at":"2022-08-09T03:30:22.267Z","dependency_job_id":null,"html_url":"https://github.com/dasch/king_konf","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/dasch/king_konf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasch%2Fking_konf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasch%2Fking_konf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasch%2Fking_konf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasch%2Fking_konf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dasch","download_url":"https://codeload.github.com/dasch/king_konf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasch%2Fking_konf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259746565,"owners_count":22905281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","ruby"],"created_at":"2024-08-03T15:00:57.421Z","updated_at":"2025-06-14T01:40:38.727Z","avatar_url":"https://github.com/dasch.png","language":"Ruby","readme":"# KingKonf\n\nKingKonf gives you a way of declaratively specifying configuration variables for your application or library. It is focused on simplicity and being able to work well with environment variables, meaning that there is no nesting or fancy structures: all configuration can be passed as strings.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'king_konf'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install king_konf\n\n## Usage\n\nIn order to specify a set configuration variables, simply subclass `KingKonf::Config` and use the DSL:\n\n```ruby\nrequire \"king_konf\"\n\nclass MyApplication::Config \u003c KingKonf::Config\n  # The prefix is used to identify environment variables. Here, we require\n  # that all environment variables used for config start with `MY_APP_`,\n  # followed by the all caps name of the variable.\n  env_prefix :my_app\n\n  # Strings are the simplest. This variable is required and *must* be set. By default,\n  # a variable is optional.\n  string :title, required: true\n\n  # Integer variables require the value to be a valid integer:\n  integer :score\n\n  # Booleans by default use \"true\", \"false\", \"1\", and \"0\" as valid values:\n  boolean :promoted\n\n  # These can be configured:\n  boolean :allow_comments, true_values: [\"yes\"], false_values: [\"no\"]\n\n  # Lists are by default comma-separated arrays of strings:\n  list :tags\n\n  # You can separate with other characters, and decode each value as another type:\n  list :codes, sep: \";\", items: :integer\n\n  # You can also provide a default value to any variable:\n  string :body, default: \"N/A\"\n\n  # You can restrict the set of allowed values:\n  string :category, allowed_values: [\"news\", \"stuff\", \"accouncements\"]\n\n  # You can provide a custom validation function:\n  integer :even_number, validate_with: -\u003e(int) { int % 2 == 0 }\nend\n```\n\nNow that we've defined a configuration class, we can initialize it. KingKonf will read the ENV and detect any variables that match the prefix:\n\n```ruby\n# These would normally be passed by the system running your app:\nENV[\"MY_APP_TITLE\"] = \"Hello, World!\"\nENV[\"MY_APP_SCORE\"] = \"85\"\nENV[\"MY_APP_PROMOTED\"] = \"true\"\nENV[\"MY_APP_ALLOW_COMMENTS\"] = \"no\"\nENV[\"MY_APP_TAGS\"] = \"greetings,introductions,articles\"\nENV[\"MY_APP_CODES\"] = \"435;2342;8678\"\n\nconfig = MyApplication::Config.new\n\n# This validates that all required variables have been set, raising\n# KingKonf::ConfigError if one is missing.\nconfig.validate!\n\nconfig.title #=\u003e \"Hello, World!\"\nconfig.score #=\u003e 85\nconfig.promoted #=\u003e true\nconfig.allow_comments #=\u003e false\nconfig.tags #=\u003e [\"greetings\", \"introductions\", \"articles\"]\nconfig.codes #=\u003e [435, 2342, 8678]\n\n# Boolean variables also get a nice query method alias:\nconfig.promoted? #=\u003e true\nconfig.allow_comments? #=\u003e false\n```\n\nIf you prefer to use a config file, that's also possible. Simply load a YAML file with `#load_file`:\n\n```ruby\nconfig.load_file(\"config/my_app.yml\")\n```\n\nA common pattern is to store config for all runtime environments in a single file and select the config based on the current environment, e.g.:\n\n```ruby\nconfig.load_file(\"config/my_app.yml\", Rails.environment)\n```\n\nIn that case, structure the config file like so:\n\n```yaml\ndevelopment:\n  title: hello\n  score: 25\n\ntest:\n  title: yolo\n  score: 13\n\nproduction:\n  title: yeah\n  score: 99\n```\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/dasch/king_konf.\n\n## License\n\nCopyright 2017 Daniel Schierbeck\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License.\n\nYou may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","funding_links":[],"categories":["Ruby Gems"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdasch%2Fking_konf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdasch%2Fking_konf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdasch%2Fking_konf/lists"}