Sha256: b6b7a443dcb3368c1f2b19cc72f1f312109340ec39c68dd0b5878f0e747ea6ca

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'fileutils'

module VagrantPhpstormTunnel
  class Configurator
    def initialize(app, env)
      @app = app
      @env = env
      @vm = nil

      @root_path = @env[:root_path].to_s
      @home_path = '.idea/vagrant'
    end

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

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

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

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

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

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

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

      if is_intellij
        setup_environment
        link_php_to_intellij
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagrant-phpstorm-tunnel-0.1.4 lib/vagrant-phpstorm-tunnel/configurator.rb
vagrant-phpstorm-tunnel-0.1.2 lib/vagrant-phpstorm-tunnel/configurator.rb