Skip to content

Commit 5d7acb0

Browse files
Fix rails default format_version
1 parent 73cc8b5 commit 5d7acb0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/active_type/marshalling.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module Marshalling
2020
# serialized with format_version = 6.1 using _dump, will always load using _load, ignoring wherever marshal_load is defined or not.
2121
# This ensures objects will always be deserialized with the method they were serialized with. We don´t need to worry about that.
2222

23-
module ActiveRecordExtension
23+
class << self
24+
attr_reader :format_version
25+
2426
def format_version=(version)
2527
case version
2628
when 6.1
@@ -30,7 +32,13 @@ def format_version=(version)
3032
else
3133
raise ArgumentError, "Unknown marshalling format: #{version.inspect}"
3234
end
35+
@format_version = version
36+
end
37+
end
3338

39+
module ActiveRecordMarshallingExtension
40+
def format_version=(version)
41+
ActiveType::Marshalling.format_version = version
3442
super(version)
3543
end
3644
end
@@ -49,4 +57,6 @@ def marshal_load(state)
4957
end
5058
end
5159

52-
ActiveRecord::Marshalling.singleton_class.prepend(ActiveType::Marshalling::ActiveRecordExtension)
60+
ActiveRecord::Marshalling.singleton_class.prepend(ActiveType::Marshalling::ActiveRecordMarshallingExtension)
61+
# Set ActiveType´s format_version to ActiveRecord´s, in case ActiveRecord uses the default value, which is set before we are loaded.
62+
ActiveType::Marshalling.format_version = ActiveRecord::Marshalling.format_version

0 commit comments

Comments
 (0)