netconstructor / acts_as_configurable Goto Github PK
View Code? Open in Web Editor NEWThis project forked from omghax/acts_as_configurable
Easy user preferences for ActiveRecord models
License: MIT License
This project forked from omghax/acts_as_configurable
Easy user preferences for ActiveRecord models
License: MIT License
= ActsAsConfigurable This plugin provides the ability to specify settings on a model class similarly to the way columns are defined in migrations, including default values. It does this by saving the settings to a TEXT column as a Hash object, serialized by YAML. While you could get the same effect by creating a column for each individual setting, this becomes cumbersome when there are more than a handful of settings, or when the settings need to be changed frequently. == Getting Started First, install the plugin: $ ./script/plugin install git://github.com/omghax/acts_as_configurable.git Next, declare acts_as_configurable in your model(s): class Blog < ActiveRecord::Base acts_as_configurable do |c| c.string :title, :default => "My Blog" c.integer :number_of_frontpage_articles, :default => 10 c.boolean :enable_akismet, :default => false end end This will define instance methods on Blog for each setting, with the specified default values. These attributes can be used in mass-assignment, validations, and pretty much anywhere else you'd use a normal database column. The available types of settings are :string, :integer, :boolean, and :object. By default, these settings will be stored inside a database column named "settings". If you'd prefer to store them elsewhere, use the :using option. class Blog < ActiveRecord::Base acts_as_configurable :using => "some_other_column" do |c| ... end end This column should be a TEXT column. === Strings First let's take a look at string settings. These behave as you would expect them to. Example: >> b = Blog.new >> b.title # => "My Blog" >> b.title = "My Custom Blog" >> b.title # => "My Custom Blog" === Integers Integer settings work similarly to string settings, but are coerced into integers when their values are set. === Booleans Here's how you deal with boolean settings. Note that these settings are flexible with what they accept during assignment. [false] nil, 0, "0", "f", "false", false [true] anything else Example: >> b.enable_akismet? # => false >> b.enable_akismet = true >> b.enable_akismet? # => true === Objects Object settings allow you to use any serializable ruby object to represent a setting's value. They should be used with care though, as changes to your code can potentially break the records in your database which reference earlier versions of classes that have changed. == License Copyright (c) 2008 Dray Lacy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.