{"id":37801329,"url":"https://github.com/nitschmann/rails-settings-manager","last_synced_at":"2026-01-16T15:26:30.435Z","repository":{"id":56890705,"uuid":"65207881","full_name":"nitschmann/rails-settings-manager","owner":"nitschmann","description":"Global settings management for Rails applications with ActiveRecord ","archived":false,"fork":false,"pushed_at":"2016-08-15T12:58:22.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-13T23:49:32.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nitschmann.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":"2016-08-08T13:48:45.000Z","updated_at":"2021-06-25T22:28:16.000Z","dependencies_parsed_at":"2022-08-20T16:00:55.426Z","dependency_job_id":null,"html_url":"https://github.com/nitschmann/rails-settings-manager","commit_stats":null,"previous_names":["fnitschmann/rails-settings-manager"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nitschmann/rails-settings-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitschmann%2Frails-settings-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitschmann%2Frails-settings-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitschmann%2Frails-settings-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitschmann%2Frails-settings-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nitschmann","download_url":"https://codeload.github.com/nitschmann/rails-settings-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitschmann%2Frails-settings-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-16T15:26:29.619Z","updated_at":"2026-01-16T15:26:30.427Z","avatar_url":"https://github.com/nitschmann.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rails-settings-manager\n\nA simple extension-plugin for Ruby on Rails application for global settings management in the Database with an easy key-value interface. It keeps track of the settings with the help of standard ActiveRecord methods.\n\n## Features\n\n* Simple management of a global settings table (or even multiple if wanted) in Ruby on Rails applications with an easy key-value interface\n* Behaves like a global Hash stored in the database of the app with full-usage of standard ActiveRecord methods for manipulation, queries and validation\n* Support for key limitations and setting-value validations in the setting models\n* Support for any kind of Object (e.g. ` integer `, ` float `, ` string ` or ` array `)\n* Also modular application structures (e.g. ` Rails::Engine `) are supported\n\n## Requirements\n\n* Ruby (Version ` \u003e= 2.1.0 `)\n* Rails (Version ` \u003e= 4.2.0 `) [Note: ` Rails V 5.0.0 ` and above should also work fine, but are not tested yet completly. If any failures might happen with it feel free to report an [Issue](https://github.com/fnitschmann/rails-settings-manager/issues)] \n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"rails-settings-manager\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rails-settings-manager\n    \n\nGenerate the required settings files:\n\n    $ rails g settings:install\n    \nIf wanted with a custom model name:\n\n    $ rails g settings:install CustomName\n\nThen run your migrations:\n\n    $ bundle exec rake db:migrate\n\n## Usage\n\n### Basic syntax\n\nThe setting syntax is easy. Create some basic settings if wanted:\n\n```ruby\nSetting.admin_username = \"admin\"\nSetting.admin_password = \"superadminpassword\"\nSetting.some_numbers = 123\nSetting.other_credentials = { :username =\u003e \"user\", :password =\u003e \"userpassword\" } \nSetting[\"array_like_setting\"] = []\n```\n\nRead them:\n\n```ruby\nSetting.some_numbers            # returns 123\nSetting[\"some_numbers\"]         # returns 123\n```\n\nChange already existing setting:\n\n```ruby\nSetting.some_numbers = 321      # returns 321\n```\n\nSet multiple at once:\n\n```ruby\nSetting.set(:foo =\u003e \"bar\", :bar =\u003e \"baz\") \n```\n\nDestroy a single setting and read it again:\n\n```ruby\nSetting.destroy!(:some_numbers) # will raise SettingsManager::Errors::SettingNotFoundError \n                                # if key not set yet\nSetting.some_numbers            # returns nil or (if set) the default value\n```\n\nGet all settings at once:\n\n```ruby\nSetting.get_all                 # returns Hash\n```\n\n### Defaults\n\nThe Gem supports ` .yml ` files which can hold default settings.\n\nTo set the default to a settings model add the following lines:\n\n```ruby\nclass Setting \u003c SettingsManager::Base\n    default_settings_config Rails.root.join(\"config/default_settings.yml\")\nend\n```\n\nThe specified file should look like:\n\n```yaml\ndefaults: \u0026defaults\n  some_key: \"some_value\"\n\ndevelopment:\n  \u003c\u003c: *defaults\n\ntest:\n  \u003c\u003c: *defaults\n\nproduction:\n  \u003c\u003c: *defaults\n```\n\nTest it:\n\n```ruby\nSetting.some_key        # returns \"some_value\" if nothing in the Database is present\n```\n\n### Key limitations\n\nThere is also an option to restrict to usage of certain keys.\n\n```ruby\nclass Setting \u003c SettingsManager::Base\n    allowed_settings_keys [:admin_username, :admin_password]\n    ...\nend\n```\n\nTest it:\n\n```ruby\nSetting.foo                     # will raise SettingsManager::Errors::KeyInvalidError\nSetting.foo = \"bar\"             # will raise SettingsManager::Errors::KeyInvalidError\nSetting.admin_username = \"xxx\"  # returns \"xxx\"\n```\nNote: Check the [Errors Module](https://github.com/fnitschmann/rails-settings-manager/blob/master/lib/settings-manager/base.rb) for more details about the exceptions\n\n### Validation\n\nValidations of the setting values for certain keys are also possible. You can use all the [ActiveRecord Validations](http://guides.rubyonrails.org/active_record_validations.html). The only exception currently is, that you can't use an ` if ` block statement in the validation ` options `.\n\nExample:\n\n```ruby\nclass Setting \u003c SettingsManager::Base\n    validates_setting :setting_to_validate,\n        :length =\u003e { :minimum =\u003e 5, :maximum =\u003e 100 }\n    ...\nend\n```\n\nTest it out:\n\n```ruby\nSetting.setting_to_validate = \"123\"     # will raise SettingsManager::Errors::InvalidError\n```\nNote: Check the [Errors Module](https://github.com/fnitschmann/rails-settings-manager/blob/master/lib/settings-manager/base.rb) for more details about the exceptions\n\n### Extension for models\n\nSettings can be bound on any already-existing ActiveRecord object (aka model). \nDefine this association like this:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n    include SettingsManager::Extension\n    \n    # Note: the following line is optional if the name of your settings model is 'Setting'\n    # if not so it is obligatory (String or Class)\n    settings_base_class Setting\nend\n```\n\nUsage:\n\n```ruby\nuser = User.find(1)\nuser.settings.foo = \"bar\"\nuser.settings.foo           # returns \"bar\"\nuser.settings.get_all       # returns { \"foo\" =\u003e \"bar\" }\n```\n\nScopes:\n\n```ruby\nUser.with_settings\n# =\u003e returns all users with any settings\n\nUser.with_settings_for(:key)\n# =\u003e returns all users with settings for 'key'\n\nUser.without_settings\n# =\u003e returns all users without any settings\n\nUser.without_settings_for(:key)\n# =\u003e returns all users without settings for 'key'\n```\n\n## Development\n\nAfter checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake rspec` to run the tests.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/fnitschmann/rails-settings-manager\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitschmann%2Frails-settings-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitschmann%2Frails-settings-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitschmann%2Frails-settings-manager/lists"}