Calling to_yaml on a ActiveType::Object does not serialize its attributes whereas to_json does and works as expected.
I am willing to PR a fix for this by overriding the init_with, encode_with methods as defined in ActiveRecord::Core (used by Psych) and adding a Yaml encoder similar to ActiveModel::AttributeSet::YAMLEncoder to serialize the virtual_attributes field instead of @attributes as is currently done by the implementation in ActiveRecord.
Example
class Person < ActiveType::Object
attribute :name
end
p = Person.new(name: "Chris")
p.to_yaml
# => "--- !ruby/object:Person\nconcise_attributes: []\nnew_record: true\nactive_record_yaml_version: 2\n"
Calling
to_yaml
on aActiveType::Object
does not serialize its attributes whereasto_json
does and works as expected.I am willing to PR a fix for this by overriding the
init_with
,encode_with
methods as defined inActiveRecord::Core
(used by Psych) and adding a Yaml encoder similar toActiveModel::AttributeSet::YAMLEncoder
to serialize thevirtual_attributes
field instead of@attributes
as is currently done by the implementation in ActiveRecord.Example