rails/rails — pull request #5217 by patrick99e99 (2012-02-29 09:23:32+00:00)
Title: added namespace option for activerecord store

To prevent method name conflicts, I have added namespacing to the ActiveRecord store. The way it works is you can now pass in a custom text to prefixr the accessor/writer method names. By passing in *true* it will namespace with the serialized database column name.

class Stuff < ActiveRecord::Base
store :item, accessors: [ :color ], namespace: true
store :thing, accessors: [ :color ], namespace: "article"
end

s = Stuff.new(item_color: "blue", article_color: "purple")

s.item_color
#=> "blue"
s.article_color
#=> "purple"

This also can be done via the store_accessor method:

store_accessor :item, :length, namespace: true
store_accessor :thing, :length, :namespace 'article'

-patrick