2014-02-25 12:15:08 -05:00
|
|
|
# Finders
|
|
|
|
|
2014-10-07 16:39:45 -04:00
|
|
|
This type of classes responsible for collection items based on different conditions.
|
|
|
|
To prevent lookup methods in models like this:
|
2014-02-25 12:15:08 -05:00
|
|
|
|
2014-02-25 12:21:53 -05:00
|
|
|
```ruby
|
2014-02-25 12:15:08 -05:00
|
|
|
class Project
|
|
|
|
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)
|
|
|
|
```
|
|
|
|
|
2014-10-07 16:39:45 -04:00
|
|
|
Better use this:
|
2014-02-25 12:15:08 -05:00
|
|
|
|
2014-02-25 12:21:53 -05:00
|
|
|
```ruby
|
2015-05-25 07:36:28 -04:00
|
|
|
issues = IssuesFinder.new(project, user, filter).execute
|
2014-02-25 12:15:08 -05:00
|
|
|
```
|
|
|
|
|
2014-10-07 16:39:45 -04:00
|
|
|
It will help keep models thiner.
|