Skip to content

Fix enum losing attribute type cast. - #39902

Merged
kamipo merged 1 commit into
rails:masterfrom
tgxworld:fix_enum_respects_attribute_override
Jul 22, 2020
Merged

kamipo merged 1 commit into
rails:masterfrom
tgxworld:fix_enum_respects_attribute_override

Conversation

@tgxworld

Copy link
Copy Markdown
Contributor

Resolves #39897

@tgxworld

Copy link
Copy Markdown
Contributor Author

@kamipo Can you review this for me?

cc @eileencodes @HParker

Comment on lines +185 to +190
type, options = attributes_to_define_after_schema_loads[attr]

attribute(attr, **default) do |subtype|
if type && !type.is_a?(Proc)
subtype = _lookup_cast_type(attr, type, options)
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to

type, options = attributes_to_define_after_schema_loads[attr_name]
attribute(attr_name) do |cast_type|
if type && !type.is_a?(Proc)
cast_type = _lookup_cast_type(attr_name, type, options)
end

@kamipo
kamipo merged commit 6ffc813 into rails:master Jul 22, 2020
@tgxworld
tgxworld deleted the fix_enum_respects_attribute_override branch July 22, 2020 08:34
@tgxworld

Copy link
Copy Markdown
Contributor Author

Thank you for the review @kamipo 👍

kamipo added a commit that referenced this pull request Jul 27, 2020
Originally #39882 is intended to remove `decorate_matching_attribute_type`
but leave `decorate_attribute_type` at that point, but in the
disscussion in #39882, to demonstrate removing `AttributeDecorators`
module, I've removed all decoration methods.

I wrote user-defined type decoration as inline, I wasn't sure that is
valid (meaningful) usage (that is a reason why I wasn't in a hurry to
remove that method), as I said at #39882 (comment).

In #39897 and #39902, `enum` also need to support user-defined type
decoration, so I've decided to add back `decorate_attribute_type` as
before #39882.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using non-integer enum types should still be read

2 participants