|
|
# Comments
|
|
|
### Classes and Class-like (Concerns)
|
|
|
Comment explaining what it does. In the case methods need to be overridden by the extending/including class, these need to be specified.
|
|
|
|
|
|
Exceptions:
|
|
|
* Controllers
|
|
|
* Models
|
|
|
|
|
|
### Methods
|
|
|
Every method should have a method comment explaining what it does. Any parameter should be defined with `@param name [Type(s)] explanation` and return types should be defined with `@return [Type(s)]`.
|
|
|
|
|
|
```ruby
|
|
|
# Paginates the given relation with the given amount of elements per page.
|
|
|
#
|
|
|
# @param relation [ActiveRecord::Relation] the relation
|
|
|
# @param amount [Integer, Nil] the amount of elements on a page (Default: 25)
|
|
|
#
|
|
|
# @return [ActiveRecord::Relation] the paginated relation
|
|
|
def paginate(relation, amount = nil)
|
|
|
amount ||= 25
|
|
|
...
|
|
|
end
|
|
|
```
|
|
|
|
|
|
Exceptions:
|
|
|
* Controller actions (`index`, `show`, `edit`, `update`, `new` and `create`)
|
|
|
* Controller parameter methods
|
|
|
* Overriding methods from concerns
|
|
|
|
|
|
### Partials
|
|
|
Partials should have a comment at the start of the file explaining what the partial displays and which parameters need to/can be passed to it.
|
|
|
|
|
|
```ruby
|
|
|
<%#
|
|
|
Partial for a table of projects.
|
|
|
|
|
|
Parameters:
|
|
|
* @param projects [ActiveRecord::Relation] the projects to display
|
|
|
* @param links [Boolean] if the rows of the table should link to the project (Default: true)
|
|
|
%>
|
|
|
```
|
|
|
|
|
|
# Style
|
|
|
### Strings
|
|
|
Use single quotes for normal strings (`'hello there'`), double quotes when doing interpolation (`"Project #{project.id}"`) or when using special characters (`"\n"`).
|
|
|
|
|
|
### If/unless
|
|
|
Prefer `if` over `unless`. (TODO: Update rubocop).
|
|
|
|
|
|
Quick return statements are allowed but require a newline after the quick return:
|
|
|
```ruby
|
|
|
def bla
|
|
|
return if <some condition>
|
|
|
|
|
|
<more code>
|
|
|
end
|
|
|
|
|
|
def bla
|
|
|
# Do not allow <x>
|
|
|
return nil unless <some condition>
|
|
|
|
|
|
# If empty, return
|
|
|
return 'No results' if <some other condition>
|
|
|
|
|
|
<more code>
|
|
|
end
|
|
|
```
|
|
|
|
|
|
|