shlogg · Early preview
Augusts Bautra @augustsbautra

Rails Models With Concerning Macro For Grouping Methods

Concerning` macro in Rails models: group methods for convenience, but use with caution to avoid "secret API". Use for sub-groups of behavior within a model, spec them in the model spec.

Turns out Rails models have a neat macro - concerning. It allows defining an inline concern.
Docs: https://api.rubyonrails.org/classes/Module/Concerning.html

  
  
  Discussion

On the one hand, it's convenient for grouping methods, and have that grouping exist in an actual code structure, not just come comment block, and it's helpful to have that grouping live in the same file.
On the other hand, unfortunately, the separation of the concern from the model is so weak as to be nonexistent - nothing stops us from calling model methods in the concern module, leading to the popular flaw of secret...