30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/test_seeds.rb', line 30
def seeds(name = nil, &block)
set_callback(:seed, :before) do
pre_vars = self.instance_variables
self.instance_eval &block
post_vars = self.instance_variables
(post_vars - pre_vars).each do |seed_var|
seed_name = seed_var.to_s[1..-1]
next if seed_name.starts_with?("_")
seed_accessor = self.set_seed_fixture(seed_name, self.instance_variable_get(seed_var))
self.instance_variable_set(seed_var, nil)
defined_seeds = self.class.defined_seeds
defined_seeds[name] ||= {}
defined_seeds[name][seed_var] = seed_accessor
end
end
end
|