= Property sets This gem is a way for you to use a basic "key/value" store for storing attributes for a given model in a relational fashion where there's a row per attribute. Alternatively you'd need to add a new column per attribute to your main table, or serialize the attributes and their values. == Description You configure the allowed stored properties by specifying these in the model: class Account < ActiveRecord::Base property_set :settings do property :version, :default => "v1.0" property :featured, :protected => true property :activated end property_set :texts do property :epilogue end end The declared properties can then be accessed runtime via the defined association: # Return the version record for this account - or a new record if none exists account.settings.version # Create (or update) the version record with default value account.settings.version.create # Create (or update) the version record with the given value account.settings.version.create(:value => "v1.1") # Destroy the version record account.settings.version.destroy === Convenience methods On top of the basic access paths, there are some short cuts, mainly convenience methods for dealing with booleans: # immediately changes the value of the setting account.settings.version=("v3.0") # coerces the setting to boolean AR style account.settings.featured? # sets the value of this setting to a true value account.settings.featured.enable # sets the value of this setting to a false value account.settings.featured.disable === Bulk operations Stored properties can also be updated with the update_attributes and update_attributes! methods by enabling nested attributes. Like this (from the test cases): @account.texts_attributes = [ { :name => "foo", :value => "1" }, { :name => "bar", :value => "0" } ] And for existing records: @account.update_attributes!(:texts_attributes => [ { :id => @account.texts.foo.id, :name => "foo", :value => "0" }, { :id => @account.texts.bar.id, :name => "bar", :value => "1" } ]) Using nested attributes is subject to implementing your own security measures for mass update assignments. Alternatively, it is possible to use a custom hash structure: params = { :property_sets => { :settings => { :version => "v4.0", :featured => "1" }, :texts => { :epilogue => "Wibble wobble" } }} @account.update_attributes(params) The above will not update +featured+ as this has the protected flag set and is hence protected from mass updates. === View helpers We support a single convenience mechanism for building forms and putting the values into the above hash structure. So far, we only support check boxes: <% form_for(:account, :html => { :method => :put }) do |f| %>