Skip to content

Instantly share code, notes, and snippets.

@solnic
Last active February 4, 2017 10:17
Show Gist options
  • Save solnic/c250fabf1d85764fa9a8 to your computer and use it in GitHub Desktop.
Save solnic/c250fabf1d85764fa9a8 to your computer and use it in GitHub Desktop.
Upcoming command composition in ROM
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