Last active
February 4, 2017 10:26
-
-
Save adz/660bf55fc2c822dff86f to your computer and use it in GitHub Desktop.
This file contains 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
command_builder = rom.command # no relation given, so get builder | |
nested_command = command_builder.create(user: :users) do |user| | |
user.create(:books) | |
end | |
# equivalent: | |
nested_command = rom.command({user: :users}, [:create, [:books, [:create]]]) | |
# equivalent | |
user_create = rom.command(:users)[:create] | |
books_create = rom.comand(:books)[:create] | |
nested_command = -> input { | |
user_create.call(input[:user]).combine( | |
books_create.call(input[:user][:books]) | |
) | |
} | |
# and books_create command is built to take (books, user) | |
# and gets partially applied with :books, so on combine | |
# it receives output of user_create command, which will be a user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ROM Commands
The Command Registry holds commands for one relation
The Container holds Command Registries (looked up by relation)
Inside Command Registry you access defined commands:
Method missing works too:
These commands must be given their input as for the relation, so typically a hash, or an array of hashes. It’s defined in #execute of the command.
Combining commands — the fun stuff :)
Want to combine multiple relations/commands.
We have ‘combine’
HOW does it work? Combine just passes through output of left to right…
and it’s been partially applied with task,
and command is defined to take (task, user)
GRAPH commands
In practice input given will be nested too, so want to provide a ‘path’ into the input for some commands.
This <graph_definition> is an array of relation and command lookups, where the relation can be given with associated input path.
Relation name is assumed a key as input path if none given...
Example:
Graph DSL
THEN there’s graph DSL