Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ability for extension/form generators to append to existing seeds…

….rb file instead of overwriting it. #1532.
  • Loading branch information...
commit 60027d2858a26a2a3b45d7df30908bb6989aa436 1 parent b00695c
@ugisozols ugisozols authored
View
2  core/lib/generators/refinery/engine/engine_generator.rb
@@ -20,6 +20,8 @@ def generate
merge_locales!
+ copy_or_merge_seeds!
+
append_extension_to_gemfile!
finalize_extension!
View
2  core/lib/generators/refinery/form/form_generator.rb
@@ -22,6 +22,8 @@ def generate
merge_locales!
+ copy_or_merge_seeds!
+
append_extension_to_gemfile!
finalize_extension!
View
22 core/lib/refinery/extension_generation.rb
@@ -139,6 +139,7 @@ def evaluate_templates!
reject_template?(f)
}.sort.each do |path|
if (template_path = extension_path_for(path, extension_name)).present?
+ next if path.to_s =~ /seeds.rb/
template path, template_path
end
end
@@ -209,6 +210,27 @@ def merge_locales!
end
end
+ def copy_or_merge_seeds!
+ source_seed_file = source_pathname.join("db/seeds.rb")
+ destination_seed_file = destination_pathname.join(extension_path_for(source_seed_file, extension_name))
+
+ if existing_extension?
+ # create temp seeds file
+ temp_seed_file = destination_pathname.join(extension_path_for("tmp/seeds.rb", extension_name))
+
+ # copy/evaluate seeds template to temp file
+ template source_seed_file, temp_seed_file, :verbose => false
+
+ # append temp seeds file content to extension seeds file
+ destination_seed_file.open('a+') { |file| file.puts temp_seed_file.read.to_s }
+
+ # remove temp file
+ FileUtils.rm_rf temp_seed_file
+ else
+ template source_seed_file, destination_seed_file
+ end
+ end
+
def puts_instructions!
unless Rails.env.test?
puts "------------------------"
Please sign in to comment.
Something went wrong with that request. Please try again.