vendredi 6 mars 2020

How to extend Rails models?

Say, I have a Rails model with a method:

class Order < ApplicationRecord
  def process
    do_some
    do_some_more
    do_even_more_here
  end
end

Its purpose is solely Rails-model based, meaning its actions are performed on the object itself. What would be the best design pattern to adapt if I'd want to refactor this method and move it out somewhere else?

What I've found so far is that a Decorator shouldn't be the answer as they are more view related. ServiceObject is meant to only perform calculations without the ActiveRecord object and Concerns are mixins that divide responsibilities over several (ActiveRecord) objects.

Aucun commentaire:

Enregistrer un commentaire