{"id":18513333,"url":"https://github.com/jbox-web/active_settings","last_synced_at":"2025-06-25T07:03:23.057Z","repository":{"id":146101008,"uuid":"154259436","full_name":"jbox-web/active_settings","owner":"jbox-web","description":"Settings in Rails, easy ;)","archived":false,"fork":false,"pushed_at":"2025-03-04T21:14:54.000Z","size":90,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T09:17:45.283Z","etag":null,"topics":["configuration-file","configuration-management","rails","ruby","settings"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbox-web.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-23T03:57:22.000Z","updated_at":"2025-03-04T21:14:58.000Z","dependencies_parsed_at":"2024-04-09T01:42:53.273Z","dependency_job_id":"0e410927-213b-41b7-b9e1-51c1766e1a3f","html_url":"https://github.com/jbox-web/active_settings","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jbox-web/active_settings","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Factive_settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Factive_settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Factive_settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Factive_settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbox-web","download_url":"https://codeload.github.com/jbox-web/active_settings/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Factive_settings/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261823686,"owners_count":23215140,"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-file","configuration-management","rails","ruby","settings"],"created_at":"2024-11-06T15:37:39.667Z","updated_at":"2025-06-25T07:03:23.028Z","avatar_url":"https://github.com/jbox-web.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveSettings\n\n[![GitHub license](https://img.shields.io/github/license/jbox-web/active_settings.svg)](https://github.com/jbox-web/active_settings/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/jbox-web/active_settings.svg)](https://github.com/jbox-web/active_settings/releases/latest)\n[![CI](https://github.com/jbox-web/active_settings/workflows/CI/badge.svg)](https://github.com/jbox-web/active_settings/actions)\n[![Code Climate](https://codeclimate.com/github/jbox-web/active_settings/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/active_settings)\n[![Test Coverage](https://codeclimate.com/github/jbox-web/active_settings/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/active_settings/coverage)\n\nSettings in Rails.\n\nIt's heavily based on [config](https://github.com/rubyconfig/config) gem.\n\nI made my own because I don't like the idea of having a [ghost class globally accessible](https://github.com/rubyconfig/config#accessing-the-settings-object) that I can't modify (What if I want to add some convenient methods on `Settings`?).\n\n## Installation\n\nPut this in your `Gemfile` :\n\n```ruby\ngit_source(:github){ |repo_name| \"https://github.com/#{repo_name}.git\" }\n\ngem 'active_settings', github: 'jbox-web/active_settings', tag: '1.1.0'\n```\n\nthen run `bundle install`.\n\n\n## Usage\n\n### 1. Define your class\n\nInstead of defining a `Settings` constant for you, that task is left to you. Simply create a class in your application\nthat looks like:\n\n```ruby\nclass Settings \u003c ActiveSettings::Base\n  source    Rails.root.join('config', 'settings.yml')\n  namespace Rails.env\nend\n```\n\nName it `Settings`, name it `Config`, name it whatever you want. Add as many or as few as you like. A good place to put\nthis file in a Rails app is `config/settings.rb`\n\n\n### 2. Create your settings\n\nNotice above we specified an absolute path to our settings file called `settings.yml`. This is just a typical YAML file.\nAlso notice above that we specified a namespace for our environment.  A namespace is just an optional string that corresponds\nto a key in the YAML file.\n\nUsing a namespace allows us to change our configuration depending on our environment:\n\n```yaml\n# config/settings.yml\ndefaults: \u0026defaults\n  cool:\n    saweet: nested settings\n  neat_setting: 24\n  awesome_setting: \u003c%= \"Did you know 5 + 5 = #{5 + 5}?\" %\u003e\n\ndevelopment:\n  \u003c\u003c: *defaults\n  neat_setting: 800\n\ntest:\n  \u003c\u003c: *defaults\n\nproduction:\n  \u003c\u003c: *defaults\n```\n\nKeys are both accessible with a string or a symbol.\n\n\n### 3. Access your settings\n\nYou can use different methods to access to values :\n\n* by using method chains :\n\n```ruby\n\u003e\u003e Rails.env\n=\u003e \"development\"\n\n\u003e\u003e Settings.cool\n=\u003e \"#\u003cActiveSettings::Config ... \u003e\"\n\n\u003e\u003e Settings.cool.saweet\n=\u003e \"nested settings\"\n\n\u003e\u003e Settings.neat_setting\n=\u003e 800\n\n\u003e\u003e Settings.awesome_setting\n=\u003e \"Did you know 5 + 5 = 10?\"\n```\n\n* by using `fetch` method :\n\n```ruby\n\u003e\u003e Settings.cool.fetch(:saweet)\n=\u003e \"nested settings\"\n\n\u003e\u003e Settings.cool.fetch('saweet')\n=\u003e \"nested settings\"\n```\n\nYou can provide default value :\n\n```ruby\n\u003e\u003e Settings.cool.fetch(:foo, 'bar')\n=\u003e \"bar\"\n\n\u003e\u003e Settings.cool.fetch(:foo) { 'bar' }\n=\u003e \"bar\"\n```\n\n* by using `[]` accessor :\n\n```ruby\n\u003e\u003e Settings[:cool][:saweet]\n=\u003e \"nested settings\"\n\n\u003e\u003e Settings['cool']['saweet']\n=\u003e \"nested settings\"\n```\n\n* by using `dig` method :\n\n```ruby\n\u003e\u003e Settings.dig(:cool, :saweet)\n=\u003e \"nested settings\"\n\n\u003e\u003e Settings.dig('cool', 'saweet')\n=\u003e \"nested settings\"\n```\n\n* by using `key?` method :\n\n```ruby\n\u003e\u003e Settings.cool.key?(:saweet)\n=\u003e \"true\"\n\n\u003e\u003e Settings.cool.key?('saweet')\n=\u003e \"true\"\n```\n\nYou can use these settings anywhere, for example in a model:\n\n```ruby\nclass Post \u003c ActiveRecord::Base\n  self.per_page = Settings.pagination.posts_per_page\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Factive_settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbox-web%2Factive_settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Factive_settings/lists"}