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

New cop for extracting complex callbacks code into separate methods #1387

Open
fatkodima opened this issue Nov 21, 2024 · 0 comments
Open

New cop for extracting complex callbacks code into separate methods #1387

fatkodima opened this issue Nov 21, 2024 · 0 comments

Comments

@fatkodima
Copy link
Contributor

When the model have some callback code defined inline via a proc, you need to read the actual code to understand what it does.
This can not be a problem of course for simple one-liners, but for other cases it is better when it is given an explicit name.

# bad
class User < ApplicationRecord
  before_validation do
    foo
    bar
    ...
    baz
  end
end

# good
class User < ApplicationRecord
  before_validation :do_something

  private
    def do_something
      foo
      bar
      ...
      baz
    end
end

# ok
class User < ApplicationRecord
  before_validation -> { do_something }
end

The same applies to controllers/jobs/mailers callbacks.

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

No branches or pull requests

1 participant