Code Monkey home page Code Monkey logo

acts_as_configurable's Introduction

= 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.

acts_as_configurable's People

Stargazers

Christian Hochfilzer avatar

Watchers

Christian Hochfilzer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.