Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease number of deprecation warnings in Ruby 2.7 #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richardboehme
Copy link
Contributor

We experienced some deprecation warnings after upgrading one of our apps to Ruby 2.7.5. This patch removes all deprecation warnings occurring when running the tests of the cells gem.

@@ -9,7 +9,7 @@ def self.included(base)

module ClassMethods
def build(*args)
build!(self, *args).new(*args) # Declarative::Builder#build!.
build!(self, *args, **{}).new(*args) # Declarative::Builder#build!.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is an appropriate fix, but it seems to work!

Copy link
Member

Choose a reason for hiding this comment

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

Are you guys using Cells' builder features, and if yes, what do your builders look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No we are not using them. I just found this by running the tests with ruby 2.7 and the tests still pass for ruby 3 so I think this may work.

constant = name.is_a?(Class) ? name : class_from_cell_name(name)
constant.(*args, **kws, &block)
constant.(*args, &block)
Copy link
Member

Choose a reason for hiding this comment

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

What warning does removing **kws resolve for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the warning we got:

/home/richard/.rvm/gems/ruby-2.7.5/bundler/gems/cells-88796e3a29cb/lib/cell/view_model.rb:67: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/richard/.rvm/gems/ruby-2.7.5/bundler/gems/cells-88796e3a29cb/lib/cell/view_model.rb:31: warning: The called method `cell' is defined here

I was wondering why it wasn't failing with ruby 3 and figured out that those keyword arguments are not used because the instance method cell helper was passing the option as a positional argument anyways (so the kws hash would always be empty in ruby 3).

@apotonick
Copy link
Member

apotonick commented Mar 31, 2022

Overally, I'm very happy you address this as I've been trying to make Cells ready for Ruby 3.0. 🌞 I see a problem, however, in our old signatures: we were allowing all kinds of argument chains such, and maybe a first step would be to define expected arguments. For example, the #cell helper should probably be def cell(model=nil, **options) and not allow positionals.

Are you happy to discuss this approach?

@richardboehme
Copy link
Contributor Author

Overally, I'm very happy you address this as I've been trying to make Cells ready for Ruby 3.0. sun_with_face I see a problem, however, in our old signatures: we were allowing all kinds of argument chains such, and maybe a first step would be to define expected arguments. For example, the #cell helper should probably be def cell(model=nil, **options) and not allow positionals.

Are you happy to discuss this approach?

That sounds like a way better approach than what I was going for! I just wanted to quickly fix those warnings 😅 Having defined expected arguments is definitely better than what we have right now. How do you want to approach this refactoring? I feel like it might lead to breaking other cells-related gems (I'm thinking trailblazer/cells-rails for example). Also it might break some user's cells invocation when they pass the options as a positional right now (however this would be an easy fix for them).

@apotonick
Copy link
Member

Komm mal hier her https://trailblazer.zulipchat.com @richardboehme 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants