clio / polymorphic_integer_type

MIT License
37 stars 35 forks source link

handle ruby 3.x keyword arguments delegation #53

Closed rcugut closed 1 year ago

rcugut commented 2 years ago

This adds code compatibility with ruby 3.x changes in regard the delegation of positional splat arguments.

More info in the official ruby blog post explaining this change: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

The existing code breaks for ruby 3.x:

ArgumentError: wrong number of arguments (given 3, expected 1..2)
# ./gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1457:in `has_many'
# ./lib/polymorphic_integer_type/extensions.rb:90:in `has_many'

I tested (locally) and the code changes are backward compatible for ruby 2.6 and 2.7.

rcugut commented 2 years ago

PS: I see the CI Github Actions setup is "hardcoded" to use ruby 2.6

https://github.com/clio/polymorphic_integer_type/blob/d27d2769dee2073aa0979b1bf6506196d167a4ac/.github/workflows/ci.yml#L26-L29

olegantonyan commented 2 years ago

Thank you @rcugut This already works in production, but I also had to change few things to make make it work in Rails 7. Hope this will be merged soon

rcugut commented 2 years ago

Thank you @rcugut This already works in production, but I also had to change few things to make make it work in Rails 7. Hope this will be merged soon

Thank you @olegantonyan

I just updated to Rail 7 too, and I had to only change the gemspec to for activerecord 7, and it works.

I'll watch for an update and use the published gem when you push it. Thank you

olegantonyan commented 2 years ago

If only I was a contributor here, he-he :) For Rails 7 I've changed this https://github.com/olegantonyan/polymorphic_integer_type/commit/c01f473d3010dcd512e043791268765f7a305a37 b/c otherwise it broke non-integer polymorphic association. Also, it doesn't work with STI (when has_many points to model using STI). It's not crucial for me, but maybe someone is already working on proper fix for this