Is there a way to automatically assign values ββto types that are stored using ActiveRecord :: Base.store?
Take this completely impractical example:
class User < ActiveRecord::Base
store :settings, accessors: [ :age ]
end
user = User.new(age: '10')
user.age
I know that I can just override the reading method for age to convert it to an integer, but I was curious if there is an undocumented way to do this.
Trying to avoid this:
class User < ActiveRecord::Base
store :settings, accessors: [ :age ]
def age
settings[:age].to_i
end
end
user = User.new(age: '10')
user.age
Update
Looking for something like:
class User < ActiveRecord::Base
store :settings, accessors: {:age => :to_i}
end
Or:
class User < ActiveRecord::Base
store :settings, accessors: {:age => Integer}
end
source
share