ActiveRecord::Store is like a simple key/value store that you use for dynamic attributes in a relational databases, for examples storing settings without creating new cols.But to make it really useful, you need some sort of typecasting which from docs should be done like this:
class Song < ActiveRecord::Base
Uses a stored integer to hold the volume adjustment of the song
store :settings, accessors: [:volume_adjustment]
def volume_adjustment=(decibels)
super(decibels.to_i)
end
def volume_adjustment
super.to_i
end
end
As you can see the idea that you should be overwriting the default accessors to type casting twice(once for getter & once for setter). so if you have 10attributes, you have to define 20methods in your model(verbose & not DRY). Further, this doesn’t handle default values. Hence, I propose following new syntax
store(:settings) do
boolean :allow_custom_url, default: false
integer :volume
integer :update_interval, default: 60
string :blurb
string :body_background, default: “light”
string :contrast, default: “red”
end
Feedback welcome