Skip to content

Instantly share code, notes, and snippets.

@henrik
Created October 9, 2015 22:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save henrik/bff879a97f7df44a8830 to your computer and use it in GitHub Desktop.
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
@henrik
Copy link
Author

henrik commented Oct 13, 2015

Note: the feature that enables this may not be long for this world… :) http://thepugautomatic.com/2015/10/how-to-expect-to-in-elixir/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment