We want to use the Whole Value pattern in our Rails4 application.
We know that in Rails5, if we want
OurModel to use a custom
NameType Whole Value type for the attribute
:name, we can define our custom type similar to this:
class NameType < ActiveModel::Type::Value
and then in
class OurClass < ApplicationRecord
attribute :name, NameType.new
which provides us with completely transparent serialization when saving the model to the DB and casting to the Whole Value Type when creating the model from the DB or manually (this is described in this RubyTapas episode, subscriber-only).
Can something similarly elegant be achieved in Rails 4? If so, how?