Class: ProvisionVagrant::Generator
- Inherits:
-
Object
- Object
- ProvisionVagrant::Generator
- Defined in:
- lib/generator.rb
Instance Method Summary collapse
- #copy_vagrantfile ⇒ Object
- #create_new_project_dir ⇒ Object
- #default_config_path ⇒ Object
- #default_post_hook_path ⇒ Object
- #default_vagrantilfe_path ⇒ Object
- #delete ⇒ Object
- #dev_box_dir_path ⇒ Object
- #generate ⇒ Object
-
#initialize(opts = {}) ⇒ Generator
constructor
A new instance of Generator.
- #project_path ⇒ Object
- #target_vagrantfile_path ⇒ Object
- #vagrantfile_path ⇒ Object
- #vagrantfile_string ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 |
# File 'lib/generator.rb', line 7 def initialize(opts = {}) @opts = opts @project_name = opts[:project_name] @initializer = PvInitializer.new(opts) @config_opts = read_config_opts(opts[:config]) end |
Instance Method Details
#copy_vagrantfile ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generator.rb', line 54 def copy_vagrantfile vars = config_opts.merge({ project_name: project_name }) interpolator = Interpolator.new( { vars: vars, input: vagrantfile_string }) interpolated = interpolator.interpolate ProvisionVagrant.write_string_to_File(interpolated, target_vagrantfile_path) if File.exist?(target_vagrantfile_path) puts "Copied #{vagrantfile_path} (and inerpolated its vars) to: #{target_vagrantfile_path}" else ProvisionVagrant.help("Error: there was a problem copying over your Vagrantilfe.template (dfeault) from #{vagrantfile_path} to #{target_vagrantfile_path}") end end |
#create_new_project_dir ⇒ Object
49 50 51 52 |
# File 'lib/generator.rb', line 49 def create_new_project_dir puts "Creating #{project_name} directory: #{dev_box_dir_path}" FileUtils.mkdir_p(dev_box_dir_path) end |
#default_config_path ⇒ Object
67 68 69 |
# File 'lib/generator.rb', line 67 def default_config_path @_default_config_path ||= File.join(initializer.user_directory, PROVISION_VAGRANT_CONFIG_FILE_NAME) end |
#default_post_hook_path ⇒ Object
75 76 77 |
# File 'lib/generator.rb', line 75 def default_post_hook_path @_default_post_hook_path ||= File.join(initializer.user_directory, POST_HOOK_FILE_NAME) end |
#default_vagrantilfe_path ⇒ Object
71 72 73 |
# File 'lib/generator.rb', line 71 def default_vagrantilfe_path @_default_vagrantfile_path ||= File.join(initializer.user_directory, VAGRANTFILE_NAME) end |
#delete ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generator.rb', line 30 def delete [default_config_path, default_vagrantilfe_path, default_post_hook_path].each do |file_name| if File.exist?(file_name) puts "Removing: #{file_name}" FileUtils.rm_f(file_name) end end end |
#dev_box_dir_path ⇒ Object
45 46 47 |
# File 'lib/generator.rb', line 45 def dev_box_dir_path @_dev_box_dir_path ||= File.join(initializer.user_directory, project_name, "dev-box/") end |
#generate ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generator.rb', line 14 def generate puts "\nNew box name: #{project_name}" create_new_project_dir if !File.exist?(dev_box_dir_path) ProvisionVagrant.help("Error: there was a problem creating target project directory: #{dev_box_dir_path}") end copy_vagrantfile puts "\nNext, cd into your new project directory: #{dev_box_dir_path}" puts "\nAnd start/provision your new vagrant box:\n\n vagrant up\n" puts "\nOnce your vagrant vm is running, ssh in as usual:\n\n vagrant ssh\n" puts "\nThe first time you login, run the post hooks installation script:\n\n ./#{POST_HOOK_FILE_NAME}\n" puts "\nSuccess! Exiting.\n" end |
#project_path ⇒ Object
41 42 43 |
# File 'lib/generator.rb', line 41 def project_path @_project_path ||= File.join(initializer.user_directory, project_name) end |
#target_vagrantfile_path ⇒ Object
83 84 85 |
# File 'lib/generator.rb', line 83 def target_vagrantfile_path @_target_vagrantfile_path ||= File.join(dev_box_dir_path, VAGRANTFILE_TARGET_NAME) end |
#vagrantfile_path ⇒ Object
79 80 81 |
# File 'lib/generator.rb', line 79 def vagrantfile_path @_vagrantfile_path ||= (opts[:template] || default_vagrantilfe_path) end |
#vagrantfile_string ⇒ Object
87 88 89 |
# File 'lib/generator.rb', line 87 def vagrantfile_string File.read(vagrantfile_path) end |