Class: VagrantWizard::API

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-wizard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPI

Returns a new instance of API.



18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-wizard.rb', line 18

def initialize
  @config_path = './config.yml'
  @defaults_path = './config.defaults.yml'
  @wizard_path = './config.wizard.yml'
  @presets_dir_path = './wizard-presets'
  @prompt_presets = true
  @prompt_overwrite = true
  @advanced = false
end

Instance Attribute Details

#advancedObject

Returns the value of attribute advanced.



16
17
18
# File 'lib/vagrant-wizard.rb', line 16

def advanced
  @advanced
end

#config_pathObject

Returns the value of attribute config_path.



10
11
12
# File 'lib/vagrant-wizard.rb', line 10

def config_path
  @config_path
end

#defaults_pathObject

Returns the value of attribute defaults_path.



11
12
13
# File 'lib/vagrant-wizard.rb', line 11

def defaults_path
  @defaults_path
end

#presets_dir_pathObject

Returns the value of attribute presets_dir_path.



13
14
15
# File 'lib/vagrant-wizard.rb', line 13

def presets_dir_path
  @presets_dir_path
end

#prompt_overwriteObject

Returns the value of attribute prompt_overwrite.



15
16
17
# File 'lib/vagrant-wizard.rb', line 15

def prompt_overwrite
  @prompt_overwrite
end

#prompt_presetsObject

Returns the value of attribute prompt_presets.



14
15
16
# File 'lib/vagrant-wizard.rb', line 14

def prompt_presets
  @prompt_presets
end

#wizard_pathObject

Returns the value of attribute wizard_path.



12
13
14
# File 'lib/vagrant-wizard.rb', line 12

def wizard_path
  @wizard_path
end

Instance Method Details

#require_configObject



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
# File 'lib/vagrant-wizard.rb', line 28

def require_config
  if File.exist?(@config_path)
    return YAML.load_file(@config_path)
  end

  puts "You do not have a configuration file set up for this Vagrant environment."

  confirmationString = 'Would you like to create a configuration file using Vagrant Wizard?'
  confirmation = TTY::Prompt.new

  if (confirmation.yes?(confirmationString))
    promptDisplay = PromptDisplay.new

    promptDisplay.wizard_path = @wizard_path
    promptDisplay.defaults_path = @defaults_path
    promptDisplay.presets_dir_path = @presets_dir_path
    promptDisplay.config_path = @config_path
    promptDisplay.prompt_presets = @prompt_presets
    promptDisplay.prompt_overwrite = @prompt_overwrite
    promptDisplay.advanced = @advanced
    
    promptDisplay.display

    # User has been prompted, check again for config file.
    if File.exist?(@config_path)
      return YAML.load_file(@config_path)
    end
  end

  return nil
end