Skip to content

Instantly share code, notes, and snippets.

@RichardJordan
Last active February 15, 2019 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardJordan/1afe9669830441da1b1c8e66f3a3061a to your computer and use it in GitHub Desktop.
Save RichardJordan/1afe9669830441da1b1c8e66f3a3061a to your computer and use it in GitHub Desktop.
UseCases pattern spike - part 1 - just for fun!
# 1. So, we are all factoring out of our controllers into Query
# Objects, Command Objects and Service Objects, to name a few,
# right?
#
# But all of that knowledge about which commands to call and what
# objects to create still ends up as an additional responsibility
# burden on the controller class.
#
# What if we wanted something that was as simple as registering the
# commands for a set of controller use cases, with either a command
# class to be called, or a method defined in the UseCase class?
#
# Something like this:
module UseCases
class TransactionsUseCases < UseCases::Base
register_command 'CreateNewTransaction', on: :create
register_command :find_transaction, on: :show
def find_transaction
transaction = Queries::TransactionQuery.new.find_by(id: command_args[:id])
transaction ? success(transaction) : failure
end
end
end
# part 2: https://gist.github.com/RichardJordan/39f32d18495276cbee1bf36b7eb28db2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment