Class: RippleNetworks::WarningShot::TemplateGenerator
- Inherits:
-
Object
- Object
- RippleNetworks::WarningShot::TemplateGenerator
- Includes:
- RippleNetworks::WarningShot
- Defined in:
- lib/warning_shot/template_generator.rb
Instance Method Summary collapse
-
#initialize(path = ".") ⇒ TemplateGenerator
constructor
A new instance of TemplateGenerator.
Constructor Details
#initialize(path = ".") ⇒ TemplateGenerator
Returns a new instance of TemplateGenerator.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/warning_shot/template_generator.rb', line 6 def initialize(path=".") path="." if path.nil? #Path to installed gems templates #template_path = %{#{@@lib_directory}/../config/warning_shot/} template_path = %{#{DepChecker::LIB_DIRECTORY}/../config/warning_shot/} #Make the directory if it doesnt exist unless File.directory? path begin FileUtils.mkdir_p path rescue puts "Path does not exist and could not be created!" end end DepChecker::DEP_FILES.each do |config_file| #Source template file source_path = %{#{template_path}#{config_file}.yml} #destination template file dest_path = File.join(path,%{#{config_file}.yml}) begin unless File.exists? dest_path FileUtils.cp source_path, dest_path else puts "#{dest_path} already exists!" end rescue Exception => e puts "Could not copy #{config_file}.yml to #{path}" end end #Make script directories DepChecker::SCRIPTS.each do |script_type| #Path of script folder to create script_path = File.join(path,"scripts",script_type) begin FileUtils.mkdir_p script_path begin #Listing of installed templates script_template_path = File.join(template_path,"scripts",script_type) Dir.new(script_template_path).each {|script_file| unless script_file =~ /^\./i #Dont copy hidden files script_to_copy = File.join(path,"scripts",script_type,script_file) unless File.exists? script_to_copy FileUtils.cp File.join(script_template_path,script_file), script_to_copy else puts "#{script_to_copy} already exists!" end end } rescue Exception => e puts "Failed to copy a script template from: #{script_template_path}" end rescue Exception => e puts "Could not create: #{script_path}" end end end |