Last active
December 20, 2015 23:38
-
-
Save hovsater/6213677 to your computer and use it in GitHub Desktop.
Seeda (Design concept)
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jgaskins I feel the same way. I do love the magic that
class_exec
andinstance_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
orclass_exec
andinstance_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!