Last active
February 4, 2017 10:17
-
-
Save solnic/c250fabf1d85764fa9a8 to your computer and use it in GitHub Desktop.
Upcoming command composition in ROM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rom' | |
| ROM.setup(:memory) | |
| class Users < ROM::Relation[:memory] | |
| end | |
| class Tasks < ROM::Relation[:memory] | |
| end | |
| class CreateUser < ROM::Commands::Create[:memory] | |
| relation :users | |
| register_as :create | |
| result :one | |
| def execute(user) | |
| super(user.merge(id: 1)) | |
| end | |
| end | |
| class CreateTask < ROM::Commands::Create[:memory] | |
| relation :tasks | |
| register_as :create | |
| result :one | |
| def execute(user, task) | |
| super(task.merge(user_id: user[:id])) | |
| end | |
| end | |
| rom = ROM.finalize.env | |
| users = rom.commands.users | |
| tasks = rom.commands.tasks | |
| create_user_with_task = users.create.curry(name: 'Piotr') >> tasks.create.curry(title: 'Task One') | |
| result = create_user_with_task.call | |
| puts result | |
| # {:title=>"Task One", :user_id=>1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment