Class: Nugrant::Vagrant::V2::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/nugrant/vagrant/v2/helper.rb

Class Method Summary collapse

Class Method Details

.find_project_pathString

The project path is the path where the top-most (loaded last) Vagrantfile resides. It can be considered the project root for this environment.

Copied from ‘libvagrantenvironment.rb#532` (tag: v1.6.2)

Returns:

  • (String)

    The project path to use.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nugrant/vagrant/v2/helper.rb', line 21

def self.find_project_path()
  vagrantfile_name = ENV["VAGRANT_VAGRANTFILE"]
  vagrantfile_name = [vagrantfile_name] if vagrantfile_name && !vagrantfile_name.is_a?(Array)

  root_finder = lambda do |path|
    vagrantfile = find_vagrantfile(path, vagrantfile_name)

    return path if vagrantfile
    return nil if path.root? || !File.exist?(path)

    root_finder.call(path.parent)
  end

  root_finder.call(get_vagrant_working_directory())
end

.find_vagrantfile(search_path, filenames = nil) ⇒ Pathname

Finds the Vagrantfile in the given directory.

Copied from ‘libvagrantenvironment.rb#732` (tag: v1.6.2)

Parameters:

  • path (Pathname)

    Path to search in.

Returns:

  • (Pathname)


45
46
47
48
49
50
51
52
53
# File 'lib/nugrant/vagrant/v2/helper.rb', line 45

def self.find_vagrantfile(search_path, filenames = nil)
  filenames ||= ["Vagrantfile", "vagrantfile"]
  filenames.each do |vagrantfile|
    current_path = search_path.join(vagrantfile)
    return current_path if current_path.file?
  end

  nil
end

.get_restricted_keysObject



77
78
79
80
81
82
# File 'lib/nugrant/vagrant/v2/helper.rb', line 77

def self.get_restricted_keys()
  bag_methods = Nugrant::Bag.instance_methods
  parameters_methods = V2::Config::User.instance_methods

  (bag_methods | parameters_methods).map(&:to_s)
end

.get_used_restricted_keys(hash, restricted_keys) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/nugrant/vagrant/v2/helper.rb', line 84

def self.get_used_restricted_keys(hash, restricted_keys)
  keys = []
  hash.each do |key, value|
    keys << key if restricted_keys.include?(key)
    keys += get_used_restricted_keys(value, restricted_keys) if value.kind_of?(Hash)
  end

  keys.uniq
end

.get_vagrant_working_directoryPathname

Returns Vagrant working directory to use.

Copied from ‘libvagrantenvironment.rb#80` (tag: v1.6.2)

Returns:

  • (Pathname)

    The working directory to start search in.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/nugrant/vagrant/v2/helper.rb', line 62

def self.get_vagrant_working_directory()
  cwd = nil

  # Set the default working directory to look for the vagrantfile
  cwd ||= ENV["VAGRANT_CWD"] if ENV.has_key?("VAGRANT_CWD")
  cwd ||= Dir.pwd
  cwd = Pathname.new(cwd)

  if !cwd.directory?
    raise Errors::EnvironmentNonExistentCWD, cwd: cwd.to_s
  end

  cwd = cwd.expand_path
end