Skip to content

Instantly share code, notes, and snippets.

@hovsater
Last active December 20, 2015 23:38
Show Gist options
  • Save hovsater/6213677 to your computer and use it in GitHub Desktop.
Save hovsater/6213677 to your computer and use it in GitHub Desktop.
Seeda (Design concept)
Seeda.definitions do
# A simple seed
seed { Category.create! name: "Example Category" }
# Seeds can be defined in groups
define :users do
# Seeds can be named for later reference
seed(:john) { User.create! name: "John Doe" }
seed(:jane) { User.create! name: "Jane Doe" }
end
# Seeds can have dependencies
define :posts, [:users] do |users|
seed { users(:john).posts.create! title: "A post" }
seed { users(:jane).posts.create! title: "Another post" }
end
end
@hovsater
Copy link
Author

@jgaskins I feel the same way. I do love the magic that class_exec and instance_exec provide, but I don't think it's worth it if people having a hard time understanding what context the methods are executed in. At first thought, I don't think the magic happening here is too confusing, but on the other hand, a new user to gem might think so.

I guess it's a decision that have to be made on whether to use yield or class_exec and instance_exec.

One thought that popped into mind was to convert the name of the definition into singular and then use it like so: seed { user.create! foo: bar } but I think that is too much trouble of converting the name into singular as well as the confusion with the seed syntax that takes an argument.

@dbrady I will definitely look into FixJour and see if I can get some inspiration!

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