aasm
aasm copied to clipboard
Option to use `public_send` instead of `write_attribute` in AR Persistence layer?
Is your feature request related to a problem? Please describe.
AASM's ActiveRecord persistence uses write_attribute
to persist. However, this doesn't work well with attributes that are not backed by exactly a single column. I want to use AASM with it's status
attribute persisted as one of many attributes in a json column.
Describe the solution you'd like
It'd be nice to be able to support any attribute that is writable via public_send("#{atribbute_name}=", ?)
so we can use attributes via:
-
store_accessor
: https://api.rubyonrails.org/classes/ActiveRecord/Store.html -
store_model
: https://github.com/DmitryTsepelev/store_model
or any other methods that provide some form of "alternative persistence" to an ActiveRecord table wherein the attribute is not backed by a single column
Describe alternatives you've considered
# [override] Overriding this so that AASM can work with
# non-column based attributes
def write_attribute(key, value)
if key.to_sym == ':json_status`
public_send("json_status=", value)
else
super(key, value)
end
end