= magic_meta_methods == Instructions A plugin to generate many methods or "attributes" on ActiveRecord that persists data into a serialized text based column as defined by :column. This plugin is particularly useful for storing display data or meta data that isn't intended to be queried directly via SQL. It reduces the number of "one-off" columns and the clutter of serialized declarations with getter/setters on your model. == Installation ruby script/plugin install git://github.com/techwhizbang/magic_meta_methods.git == Usage === Prepare database Add this migration to the desired table(s): class MagicMetaMethods < ActiveRecord::Migration def self.up add_column :your_table_here, :magic_meta_methods, :mediumtext end def self.down remove_column :your_table_here, :magic_meta_methods end end rake db:migrate === Meta Magic Methods in action Let's suppose your model needs to store a variety of data and types, but these values don't need to be queried on, many times these values are purely for display or front end purposes. class YourModel < ActiveRecord::Base magic_meta_methods([:abstract, [:some_hash, :hash], [:some_array, :array], [:some_indifferent_hash, :indifferent_hash]], :column => 'alternate_meta') end We can now use the magic meta methods just like a regular attribute setter m = YourModel.new m.abstract= "This is a brief synopsis of magic meta methods" m.some_hash = {:a => 1, :b => 2, :c => 3} m.some_array = [["Monday", "9-5"], ["Tuesday", "9-5"], ["Wed", "Closed"]] m.some_indifferent_hash = {:dog => "Fido", :cat => "Garfield"} m.save You can retrieve the values m.some_indifferent_hash['dog'] #Fido m.abstract #This is a brief synopsis of magic meta methods m.some_array[0] #["Monday", "9-5"] === Other Problems, comments, and suggestions all welcome. techwhizbang [at] gmail dot com or visit my blog http://techwhizbang.com
Project
magic_meta_methods
magic_meta_methods uses ActiveRecord data serialization and allows for several objects by key to be stored in _one_ column while still providing the same attr_accessor behavior as if there were a column for _each_ serialized object - hence the magic 'meta' methods
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Development
Dependencies
Runtime
>= 2.3.2
Project Readme