Class: Vagrant::Hivemind::Util::Vagrantfile

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/hivemind/util.rb

Class Method Summary collapse

Class Method Details

.exist?(path = Pathname.new(Dir.pwd)) ⇒ Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/vagrant/hivemind/util.rb', line 178

def self.exist?(path = Pathname.new(Dir.pwd))
  File.exist? get_vagrant_file_from_path path
end

.generate_hivemind_vagrantfile(env, hosts, path = Pathname.new(Dir.pwd), generate = false) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vagrant/hivemind/util.rb', line 144

def self.generate_hivemind_vagrantfile(env, hosts, path = Pathname.new(Dir.pwd), generate = false)
  box_types = Vagrant::Hivemind::Constants::BOX_TYPES
  box_sizes = Vagrant::Hivemind::Constants::BOX_SIZES
  cache_path = Path.cache_path
  hivemind_home_path = Path.hivemind_home_path
  local_data_path = Path.local_data_path path
  b = binding

  template_string = ""
  File.open(File.expand_path("../../../../templates/Vagrantfile.erb", __FILE__), "r") do |f|
    template_string = f.read
  end

  template = ERB.new template_string
  template_result = template.result(b)

  if generate
    vagrant_file = File.new(Vagrant::Hivemind::Constants::VAGRANT_FILE, "w+")
  else
    vagrant_file = Tempfile.new("Hivemind_Vagrantfile", path)
  end
  vagrant_file.write template_result
  vagrant_file.close

  env.define_singleton_method :vagrantfile_name= do |vfn| @vagrantfile_name = vfn end
  env.define_singleton_method :root_path= do |root_path| @root_path = root_path end
  env.define_singleton_method :local_data_path= do |local_data_path| @local_data_path = local_data_path end
  env.vagrantfile_name = [File.basename(vagrant_file)]
  env.root_path = path
  env.local_data_path = local_data_path

  nil
end