I was confused about the usage of both simple command gem and services objects. We use services by creating a services folder in app directory and then creating classess in it. We use simple command by creating commands folder in app directory and and creating classess in it. Both of these approaches end up making services objects but what is the difference between them if they provide the same thing
CodePudding user response:
This sounds like a very specific way of how your company works. Generally speaking service objects has one public method only, it's always called the same and is used to solve a business problem. Like so:
class CreateAuditor
def self.perform(auditor_params, user, company)
.....
end
private
def any_other_method_used_in_perform end
end
"command" sounds like an anti pattern and should really be a service object. I would need examples of what this "command" class looks like to try to guess. But just ask a colleague really. Both service objects and "command" is a self made up pattern which you normally don't learn and is not a part of the standard Ruby on Rails setup.