Class: VagrantPlugins::Provider::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-provider/base-command.rb

Direct Known Subclasses

ListCommand, PickCommand, StashCommand

Defined Under Namespace

Classes: AlreadyStashedProvider, HasActiveProvider, NoActiveProvider, NoStashedProvider

Instance Method Summary collapse

Instance Method Details

#active_provider(machine_name) ⇒ Object



34
35
36
# File 'lib/vagrant-provider/base-command.rb', line 34

def active_provider(machine_name)
  providers_for(machine_name).detect { |p| p[:active] }
end

#line(msg = "") ⇒ Object



46
47
48
# File 'lib/vagrant-provider/base-command.rb', line 46

def line(msg = "")
  @env.ui.info msg
end

#machine_folderObject



42
43
44
# File 'lib/vagrant-provider/base-command.rb', line 42

def machine_folder
  @env.local_data_path.join("machines")
end

#machine_namesObject



4
5
6
# File 'lib/vagrant-provider/base-command.rb', line 4

def machine_names
  @env.machine_names
end

#machine_provider(machine_name, provider) ⇒ Object



38
39
40
# File 'lib/vagrant-provider/base-command.rb', line 38

def machine_provider(machine_name, provider)
  providers_for(machine_name).detect { |p| p[:name] == provider }
end

#provider_name(folder) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/vagrant-provider/base-command.rb', line 26

def provider_name(folder)
  folder.children(true)
    .select(&:directory?)
    .select { |f| f.join("id").file? }
    .map { |f| f.basename.to_s.to_sym }
    .first
end

#providers_for(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagrant-provider/base-command.rb', line 8

def providers_for(name)
  return [] unless machine_folder.directory?

  name = name.to_s

  machine_folder.children(true)
    .select(&:directory?)
    .map { |f| f.basename.to_s }
    .select { |f| f.start_with?(name) }
    .map do |f|
      {
        name: provider_name(machine_folder.join(f)),
        active: f == name
      }
    end
    .select { |f| f[:name] }
end