Class: Mortar::Generators::ProjectGenerator
- Defined in:
- lib/mortar/generators/project_generator.rb
Instance Method Summary collapse
Methods inherited from Base
#copy_file, #generate_file, #initialize, #inside, #mkdir
Methods included from Helpers
#action, #ask, #confirm, #copy_if_not_present_at_dest, #default_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #display_with_indent, #download_to_file, #ensure_dir_exists, #error, error_with_failure, error_with_failure=, extended, extended_into, #format_bytes, #format_date, #format_with_bang, #get_terminal_environment, #home_directory, #host, #hprint, #hputs, included, included_into, #installed_with_omnibus?, #json_decode, #json_encode, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #test_name, #ticking, #time_ago, #truncate, #warning, #with_tty, #write_to_file
Constructor Details
This class inherits a constructor from Mortar::Generators::Base
Instance Method Details
#generate_project(project_name, options) ⇒ Object
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/mortar/generators/project_generator.rb', line 23 def generate_project(project_name, ) set_script_binding(project_name, ) #TODO: This needs refactoring. Too many side effects and unnecessary #complexity. Just manage the directory structure explicitly. project_path = File.join(@dest_path, project_name) project_already_existed = File.exists?(project_path) begin mkdir project_name, :verbose => false @dest_path = File.join(@dest_path, project_name) copy_file "README.md", "README.md" copy_file "gitignore", ".gitignore" mkdir "pigscripts" inside "pigscripts" do generate_file "pigscript.pig", "#{project_name}.pig" end mkdir "controlscripts" inside "controlscripts" do mkdir "lib" inside "lib" do copy_file "__init__.py", "__init__.py" end end mkdir "macros" inside "macros" do copy_file "gitkeep", ".gitkeep" end mkdir "fixtures" inside "fixtures" do copy_file "gitkeep", ".gitkeep" end mkdir "udfs" inside "udfs" do mkdir "python" inside "python" do copy_file "python_udf.py", "#{project_name}.py" end mkdir "jython" inside "jython" do copy_file "gitkeep", ".gitkeep" end mkdir "java" inside "java" do copy_file "gitkeep", ".gitkeep" end end mkdir "lib" inside "lib" do copy_file "gitkeep", ".gitkeep" end mkdir "vendor" inside "vendor" do mkdir "controlscripts" inside "controlscripts" do mkdir "lib" inside "lib" do copy_file "__init__.py", "__init__.py" end end mkdir "pigscripts" inside "pigscripts" do copy_file "gitkeep", ".gitkeep" end mkdir "macros" inside "macros" do copy_file "gitkeep", ".gitkeep" end mkdir "udfs" inside "udfs" do mkdir "python" inside "python" do copy_file "gitkeep", ".gitkeep" end mkdir "jython" inside "jython" do copy_file "gitkeep", ".gitkeep" end mkdir "java" inside "java" do copy_file "gitkeep", ".gitkeep" end end end rescue => e #If we can't set up the project correctly and the project folder #didn't exist before - remove it. unless project_already_existed or not File.exists?(project_path) display("\nProject creation failed. Removing generated files.\n") FileUtils.remove_dir project_path end raise e end end |