{"action":"created","issue":{"url":"https://api.github.com/repos/rom-rb/rom/issues/323","labels_url":"https://api.github.com/repos/rom-rb/rom/issues/323/labels{/name}","comments_url":"https://api.github.com/repos/rom-rb/rom/issues/323/comments","events_url":"https://api.github.com/repos/rom-rb/rom/issues/323/events","html_url":"https://github.com/rom-rb/rom/pull/323","id":111580052,"number":323,"title":"Add a simple DSL for building a command graph","user":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rom-rb/rom/labels/command","name":"command","color":"bfe5bf"},{"url":"https://api.github.com/repos/rom-rb/rom/labels/feature","name":"feature","color":"009800"},{"url":"https://api.github.com/repos/rom-rb/rom/labels/in%20progress","name":"in progress","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-10-15T09:37:34Z","updated_at":"2015-10-17T16:03:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rom-rb/rom/pulls/323","html_url":"https://github.com/rom-rb/rom/pull/323","diff_url":"https://github.com/rom-rb/rom/pull/323.diff","patch_url":"https://github.com/rom-rb/rom/pull/323.patch"},"body":"This adds a DSL for building up a command graph that can handle nested input:\r\n\r\n``` ruby\r\n# to handle { user: { name: \"Jane\" } }\r\nrom.command do\r\n  create(:users, from: :user)\r\nend\r\n\r\n# to handle { user: { name: \"Jane\", task { title: \"Task\" }  } }\r\nrom.command do\r\n  create(:users, from: :user) >> create(:tasks, from: :task)\r\nend\r\n\r\n# to handle { user: { name: \"Jane\", tasks: [{ title: \"Task One\" }, { title: \"Task Two\" }] } }\r\nrom.command do\r\n  create(:users, from: :user) >> create(:tasks)\r\nend\r\n\r\n# to handle:\r\n# {\r\n#   user: {\r\n#     name: \"Jane\",\r\n#     tasks: [\r\n#       { title: \"Task One\", tags: [{ name: \"Red\"}] },\r\n#       { title: \"Task Two\", tags: [{ name: \"Blue\" }] }\r\n#     ]\r\n#  }\r\n# }\r\nrom.command do\r\n  create(:users, from: :user) >> (create(:tasks) >> create(:tags))\r\nend\r\n\r\n# to handle:\r\n# {\r\n#    user: {\r\n#      name: \"Jane\",\r\n#      tasks: [\r\n#        { title: \"Task One\", tags: [{ name: \"Red\"}] },\r\n#        { title: \"Task Two\", tags: [{ name: \"Blue\" }] }\r\n#      ],\r\n#      books: [\r\n#        { title: \"Foo\", author: { name: \"Jade\" } },\r\n#        { title: \"Bar\", author: { name: \"Joe\" } }\r\n#     ]\r\n#  }\r\n# }\r\n\r\nrom.command do\r\n  create(:users, from: :user) >> (\r\n    (create(:tasks) >> create(:tags)) +\r\n    (create(:books) >> create(:authors, from: :author))\r\n  )\r\nend\r\n\r\n# to handle input for an update:\r\n# {\r\n#   user: {\r\n#     id: 1, name: \"Jane Doe\"\r\n#   }\r\n# }\r\n#\r\n\r\nrom.command do\r\n  update(:users, from: :user) { |cmd, user| cmd.by_id(user[:id]) }\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/rom-rb/rom/issues/comments/148927256","html_url":"https://github.com/rom-rb/rom/pull/323#issuecomment-148927256","issue_url":"https://api.github.com/repos/rom-rb/rom/issues/323","id":148927256,"user":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"created_at":"2015-10-17T16:03:42Z","updated_at":"2015-10-17T16:03:42Z","body":"@robinetmiller I agree, although I just realised there's a small drawback - command graph supports passing procs for update/delete commands, and now we use blocks for building up the graph, so I dunno how to tackle it /cc @endash "}}