For-fun sketch of https://github.com/thoughtbot/ex_machina/issues/33
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
defmodule ExMachina.With do | |
def create(model, attrs, {ExMachina.With, defaults}) do | |
full_attrs = Keyword.merge(defaults, attrs) | |
IO.puts "create #{model} with #{inspect full_attrs}" | |
end | |
end | |
defmodule ExMachina do | |
def with(defaults) do | |
{ExMachina.With, defaults} | |
end | |
end | |
defmodule Run do | |
def run do | |
w = ExMachina.with(user: 123) | |
w.create(:event, name: "started") | |
w.create(:event, name: "ended") | |
end | |
end | |
Run.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: the feature that enables this may not be long for this world… :) http://thepugautomatic.com/2015/10/how-to-expect-to-in-elixir/