Class: VagrantPhpstormTunnel::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-phpstorm-tunnel/configurator.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Configurator

Returns a new instance of Configurator.



5
6
7
8
9
10
11
12
# File 'lib/vagrant-phpstorm-tunnel/configurator.rb', line 5

def initialize(app, env)
  @app = app
  @env = env
  @vm = nil

  @root_path = @env[:root_path].to_s
  @home_path = File.join(@root_path, '.idea/vagrant')
end

Instance Method Details

#call(env) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant-phpstorm-tunnel/configurator.rb', line 45

def call(env)
  @env = env
  @app.call(env)
  @vm = env[:machine]

  if is_intellij
    setup_environment
    link_php_to_intellij
  end
end

#is_intellijObject



14
15
16
# File 'lib/vagrant-phpstorm-tunnel/configurator.rb', line 14

def is_intellij
  File.exist? @root_path + '/.idea'
end


18
19
20
21
22
23
24
# File 'lib/vagrant-phpstorm-tunnel/configurator.rb', line 18

def link_php_to_intellij
  destination_path = File.join(@home_path, 'php')
  source_path = File.expand_path('../../../data/php', __FILE__)

  File.symlink(source_path, destination_path)
  File.chmod(0755, destination_path)
end

#setup_environmentObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-phpstorm-tunnel/configurator.rb', line 26

def setup_environment
  FileUtils.rm_rf(@home_path)
  FileUtils.mkdir_p(@home_path)

  if tunnel_options[:project_home]
    destination_path = File.join(@home_path, 'vm_project_dir')
    File.write(destination_path, tunnel_options[:project_home].to_s, mode: 'a')
  end

  if tunnel_options[:command_prefix]
    destination_path = File.join(@home_path, 'vm_command_prefix')
    File.write(destination_path, tunnel_options[:command_prefix].to_s, mode: 'a')
  end
end

#tunnel_optionsObject



41
42
43
# File 'lib/vagrant-phpstorm-tunnel/configurator.rb', line 41

def tunnel_options
  !@vm.nil? ? @vm.config.phpstorm_tunnel.to_hash : {}
end