Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 1.26 KB

command_objects.md

File metadata and controls

21 lines (15 loc) · 1.26 KB

Command Objects

Introduction

Commands (also known as Service Objects) are the place for the application's business logic. They allow you to simplify your models and controllers and allow them to focus on what they are responsible for. A Command should encapsulate a single user task such as registering for a new account, placing an order, publishing post.

Conventions

  • Commands go under the app/commands directory. In case when a command is a part of a module, consider placing it into the directory structure suggested by Service Modules.
  • Command name should have suffix Command.
  • Command name should contain a verb (e.g. PostPublishCommand).
  • Command should have only one public method (#perform).
  • Focus on readability of the #perform method, keep it short, simple and clear.
  • Put all business logic into private methods with a very clear, self-explanatory and meaningful names.
  • Use auxiliary_rails gem.

References