Class: VagrantPlugins::SshConfig::Action::UpdateConfig
- Inherits:
-
Object
- Object
- VagrantPlugins::SshConfig::Action::UpdateConfig
- Defined in:
- lib/vagrant-ssh-config/Action/UpdateConfig.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ UpdateConfig
constructor
A new instance of UpdateConfig.
Constructor Details
#initialize(app, env) ⇒ UpdateConfig
Returns a new instance of UpdateConfig.
6 7 8 9 |
# File 'lib/vagrant-ssh-config/Action/UpdateConfig.rb', line 6 def initialize(app, env) @app = app @env = env end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vagrant-ssh-config/Action/UpdateConfig.rb', line 11 def call(env) @app.call(env) @env[:ui].info "[vagrant-ssh-config] Updating SSH config..." config = `vagrant ssh-config #{@env[:machine].name} --host #{ENV["VAGRANT_SSH_ALIAS"]}` File.write("#{@env[:env].local_data_path}/ssh-config", config) line = "Include #{@env[:env].local_data_path}/ssh-config" file = "#{@env[:env].home_path}/ssh-configs" if File.exist?(file) if ! File.foreach(file).grep(/#{line}/).any? File.open(file, "a+") { |f| f.puts(line) } end else File.write(file, line) end end |