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.

Revisions

  1. solnic revised this gist Feb 5, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion command_composition_in_rom.rb
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,6 @@ class CreateTask < ROM::Commands::Create[:memory]
    result :one

    def execute(user, task)
    byebug
    super(task.merge(user_id: user[:id]))
    end
    end
  2. solnic created this gist Feb 5, 2015.
    42 changes: 42 additions & 0 deletions command_composition_in_rom.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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)
    byebug
    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}