debian-mirror-gitlab/app/finders/README.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
531 B
Markdown
Raw Normal View History

2014-09-02 18:07:02 +05:30
# Finders
2021-01-03 14:25:43 +05:30
These types of classes are responsible for retrieving collection items based on different conditions.
They prevent lookup methods in models like this:
2014-09-02 18:07:02 +05:30
```ruby
2021-01-03 14:25:43 +05:30
class Project < ApplicationRecord
2014-09-02 18:07:02 +05:30
def issues_for_user_filtered_by(user, filter)
# A lot of logic not related to project model itself
end
end
issues = project.issues_for_user_filtered_by(user, params)
```
2021-01-03 14:25:43 +05:30
The GitLab approach is to use a Finder:
2014-09-02 18:07:02 +05:30
```ruby
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(project, user, filter).execute
2014-09-02 18:07:02 +05:30
```
2021-01-03 14:25:43 +05:30
It will help keep models thinner.