5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/generators/germinator_generator.rb', line 5
def build_seed_file
if seed_name.nil?
puts "You must provide a germinator seed name."
return
end
puts "Seed name: #{seed_name.underscore}"
name = seed_name.underscore
if Dir["#{Rails.root}/#{Germinator::SEED_PATH}/*_#{name}.rb"].length > 0
puts "The germinator seed name provided already exists. Please select another name."
return
end
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
source_seed_file = "seed.rb"
destination_seed_file = "#{Rails.root}/#{Germinator::SEED_PATH}/#{timestamp}_#{name}.rb"
copy_file source_seed_file, destination_seed_file do |content|
content.gsub('%{class_name}', seed_name)
end
end
|