{"id":20496474,"url":"https://github.com/hardpixel/smart-settings","last_synced_at":"2025-04-13T18:21:14.121Z","repository":{"id":56896218,"uuid":"106825198","full_name":"hardpixel/smart-settings","owner":"hardpixel","description":"Persist application or record settings on ActiveRecord.","archived":false,"fork":false,"pushed_at":"2020-03-06T11:19:13.000Z","size":40,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T20:56:35.642Z","etag":null,"topics":["activerecord","gem","rails","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/hardpixel.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-10-13T13:04:58.000Z","updated_at":"2020-03-06T11:19:11.000Z","dependencies_parsed_at":"2022-08-20T17:10:13.945Z","dependency_job_id":null,"html_url":"https://github.com/hardpixel/smart-settings","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Fsmart-settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Fsmart-settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Fsmart-settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Fsmart-settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardpixel","download_url":"https://codeload.github.com/hardpixel/smart-settings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758991,"owners_count":21157071,"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":["activerecord","gem","rails","settings"],"created_at":"2024-11-15T18:07:17.317Z","updated_at":"2025-04-13T18:21:14.085Z","avatar_url":"https://github.com/hardpixel.png","language":"Ruby","readme":"# SmartSettings\n\nStores and retrieves settings on an ActiveRecord class, with support for application and per record settings.\n\n[![Gem Version](https://badge.fury.io/rb/smart_settings.svg)](https://badge.fury.io/rb/smart_settings)\n[![Build Status](https://travis-ci.org/hardpixel/smart-settings.svg?branch=master)](https://travis-ci.org/hardpixel/smart-settings)\n[![Maintainability](https://api.codeclimate.com/v1/badges/930d42bb2bf6f54a4268/maintainability)](https://codeclimate.com/github/hardpixel/smart-settings/maintainability)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'smart_settings'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install smart_settings\n\nThen run the settings generator that will create a migration and a `Setting` model:\n\n    rails g smart_settings:install\n\nAnd finally run the migrations:\n\n    rails db:migrate\n\n## Usage\n\nTo create an new setting you can use the setting generator. The format of the generator arguments is `name attribute:type:default:group`. To generate a setting with the name email:\n\n    rails g smart_settings:setting email sender:string:info@website.com domain:string:website.com:smtp user:string:smtp@website.com:smtp password:string::smtp\n\nThe command above will generate the `EmailSettings` class inside the `app/settings` folder:\n\n```ruby\nclass EmailSettings \u003c SmartSettings::Base\n  setting :sender,   :string, default: 'info@website.com'\n  setting :domain,   :string, default: 'website.com',      group: :smtp\n  setting :user,     :string, default: 'smtp@website.com', group: :smtp\n  setting :password, :string, group: :smtp\nend\n```\n\nThen you can use the `Setting` model or the `EmailSettings` class to get and set attributes:\n\n```ruby\n# Get email settings using the Setting model querying\nemail = Setting.find(:email)\n\n# Get email settings using the Setting model methods\nemail = Setting.email\n\n# Get email settings using EmailSettings class\nemail = EmailSettings\n\n# Get all setting attributes\nemail.all  # { sender: \"info@website.com\", smtp: { domain: \"website.com\", user: \"smtp@website.com\", password: nil } }\n\n# Get all setting group attributes\nemail.smtp # { domain: \"website.com\", user: \"smtp@website.com\", password: nil }\n\n# Get setting specific attributes\nemail.sender    # \"info@website.com\"\nemail.smtp_user # \"smtp@website.com\"\n\n# Update setting attributes and save them in the settings table\nemail.update sender: \"notify@website.com\", smtp_user: \"admin@website.com\"\n\n# Get setting updated attributes\nemail.sender    # \"notify@website.com\"\nemail.smtp_user # \"admin@website.com\"\n```\n\nThe `Setting` model that is created with the install generator and the settings classes the are created with the setting generator, use the [tableless](https://github.com/hardpixel/tableless) gem to act like ActiveRecord models. This makes it easy to create CRUD controllers and views like you would do with any model:\n\n```ruby\nclass SettingsController \u003c ApplicationController\n  # Show and edit actions are omitted from the example since they usually are empty\n  # New and create actions cannot be used since you cannot create new settings\n\n  before_action :set_setting, only: [:show, :edit, :update, :destroy]\n\n  def index\n    @setting = Setting.all\n  end\n\n  def update\n    if @setting.update(setting_params)\n      redirect_to setting_path(@setting), notice: 'Setting was successfully updated.'\n    else\n      render :edit\n    end\n  end\n\n  def destroy\n    @setting.destroy\n    redirect_to request.referrer, notice: 'Setting was successfully reset to defaults.'\n  end\n\n  private\n\n    def set_setting\n      @setting = Setting.find(params[:id])\n    end\n\n    def setting_params\n      params.require(:setting).permit(@setting.permitted_attributes)\n    end\nend\n```\n\n# TODO\n\n* Add support for record settings\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` 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/hardpixel/smart-settings.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardpixel%2Fsmart-settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardpixel%2Fsmart-settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardpixel%2Fsmart-settings/lists"}