{"id":18355381,"url":"https://github.com/midwire/rails3_settings","last_synced_at":"2025-04-06T12:32:01.342Z","repository":{"id":140669153,"uuid":"1881717","full_name":"midwire/rails3_settings","owner":"midwire","description":"Settings is a plugin that makes managing a table of global key, value pairs easy. Think of it like a global Hash stored in your database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you don't want to hard code into your rails app. You can store any kind of object. Strings, numbers, arrays, or any serializable object.","archived":false,"fork":false,"pushed_at":"2012-06-28T19:46:49.000Z","size":109,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-21T23:51:18.424Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/midwire.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-06-11T16:43:37.000Z","updated_at":"2019-10-14T04:16:35.000Z","dependencies_parsed_at":"2023-03-11T23:06:30.416Z","dependency_job_id":null,"html_url":"https://github.com/midwire/rails3_settings","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Frails3_settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Frails3_settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Frails3_settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwire%2Frails3_settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midwire","download_url":"https://codeload.github.com/midwire/rails3_settings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247484345,"owners_count":20946384,"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":[],"created_at":"2024-11-05T22:06:43.393Z","updated_at":"2025-04-06T12:32:01.043Z","avatar_url":"https://github.com/midwire.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Rails 3 Settings Plugin\n\nMigrated to Rails 3 from Georg Ledermann's fork of Squeegy's rails-settings plugin, which\nis Rails 2.x specific.\n\nSettings is a Rails 3 plugin that makes managing a table of global key, value pairs easy.\nThink of it like a global Hash stored in you database, that uses simple ActiveRecord\nlike methods for manipulation.  Keep track of any global setting that you dont want\nto hard code into your rails app.  You can store any kind of object.  Strings, numbers,\narrays, or any object.\n\n== Setup\n\nRequirements:\n  Rails 3.x\n\nYou must create the table used by the Settings model.  Simply run this command:\n  rails generate rails3_settings\n\nNow just put that migration in the database with:\n  rake db:migrate\n\n== Usage\n\nThe syntax is easy.  First, lets create some settings to keep track of:\n\n  Settings.admin_password = 'supersecret'\n  Settings.date_format    = '%m %d, %Y'\n  Settings.cocktails      = ['Martini', 'Screwdriver', 'White Russian']\n  Settings.foo            = 123\n  Settings.credentials    = { :username =\u003e 'tom', :password =\u003e 'secret' }\n\nNow lets read them back:\n\n  Settings.foo            # returns 123\n\nChanging an existing setting is the same as creating a new setting:\n\n  Settings.foo = 'super duper bar'\n\nFor changing an existing setting which is a Hash, you can merge new values with existing ones:\n  Settings.merge! :credentials, :password =\u003e 'topsecret'\n  Settings.credentials    # returns { :username =\u003e 'tom', :password =\u003e 'topsecret' }\n\nDecide you dont want to track a particular setting anymore?\n\n  Settings.destroy :foo\n  Settings.foo            # returns nil\n\nWant a list of all the settings?\n\n  Settings.all            # returns {'admin_password' =\u003e 'super_secret', 'date_format' =\u003e '%m %d, %Y'}\n\nYou need name spaces and want a list of settings for a give name space? Just choose your prefered named space delimiter and use Settings.all like this:\n\n  Settings['preferences.color'] = :blue\n  Settings['preferences.size'] = :large\n  Settings['license.key'] = 'ABC-DEF'\n  Settings.all('preferences.')   # returns { 'preferences.color' =\u003e :blue, 'preferences.size' =\u003e :large }\n\nSet defaults for certain settings of your app.  This will cause the defined settings to return with the\nSpecified value even if they are not in the database.  Make a new file in config/initializers/settings.rb\nwith the following:\n\n  Settings.defaults[:some_setting] = 'footastic'\n  \nNow even if the database is completely empty, you app will have some intelligent defaults:\n\n  Settings.some_setting   # returns 'footastic'\n\nSettings may be bound to any existing ActiveRecord object. Define this association like this:\n\n  class User \u003c ActiveRecord::Base\n    has_settings\n  end\n\nThen you can set/get a setting for a given user instance just by doing this:\n\n  user = User.find(123)\n  user.settings.color = :red\n  user.settings.color # returns :red\n  user.settings.all # { \"color\" =\u003e :red }\n\nI you want to find users having or not having some settings, there are named scopes for this:\n\n  User.with_settings # =\u003e returns a scope of users having any setting\n  User.with_settings_for('color') # =\u003e returns a scope of users having a 'color' setting\n  \n  User.without_settings # returns a scope of users having no setting at all (means user.settings.all == {})\n  User.without_settings('color') # returns a scope of users having no 'color' setting (means user.settings.color == nil)\n\nThat's all there is to it! Enjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwire%2Frails3_settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidwire%2Frails3_settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwire%2Frails3_settings/lists"}