Class: VagrantPlugins::Protobox::Action::SwitchConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-protobox/action/switch_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SwitchConfig

Returns a new instance of SwitchConfig.



5
6
7
# File 'lib/vagrant-protobox/action/switch_config.rb', line 5

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-protobox/action/switch_config.rb', line 9

def call(env)
  system_dir = Protobox.system_dir(env[:root_path])
  config_name = env[:config_name]
  config_dir = system_dir.join("config")
  config_local_path = File.join("data", "config", config_name + ".yml")

  # Create protobox dir if it doesn't exist
  if !File.directory?(system_dir)
    Dir.mkdir(system_dir)
  end

  # Write the config file
  File.open(config_dir, 'w') do |file|
    file.write(config_local_path)
  end

  env[:ui].info(I18n.t("vagrant_protobox.actions.switch_config.switched",
                       :name => config_name))

  @app.call(env)
end