Class: Dkdeploy::TestEnvironment::Application

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/dkdeploy/test_environment/application.rb

Overview

Test application for capistrano with vagrant

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

#assets_path, #capistrano_configuration_fixtures_path, #config_dev_path, #current_path, #deploy_to, #gem_root, #maintenance_config_file_path, #releases_path, #remote_tmp_path, #server_url, #shared_path, #stage, #template_path, #test_app_path, #tmp_path

Constructor Details

#initialize(base, hostname, ssh_config = {}) ⇒ Application

Returns a new instance of Application.



22
23
24
25
26
# File 'lib/dkdeploy/test_environment/application.rb', line 22

def initialize(base, hostname, ssh_config = {})
  Dkdeploy::TestEnvironment::Constants.class_variable_set :@@root, base
  @remote = Dkdeploy::TestEnvironment::Remote.new hostname, ssh_config
  @mysql_connection_settings = {}
end

Instance Attribute Details

#mysql_connection_settingsObject

Returns the value of attribute mysql_connection_settings.



20
21
22
# File 'lib/dkdeploy/test_environment/application.rb', line 20

def mysql_connection_settings
  @mysql_connection_settings
end

#remoteDkdeploy::TestEnvironment::Remote (readonly)



16
17
18
19
20
21
22
23
24
25
26
27
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/dkdeploy/test_environment/application.rb', line 16

class Application
  include Dkdeploy::TestEnvironment::Constants

  attr_reader :remote
  attr_accessor :mysql_connection_settings

  def initialize(base, hostname, ssh_config = {})
    Dkdeploy::TestEnvironment::Constants.class_variable_set :@@root, base
    @remote = Dkdeploy::TestEnvironment::Remote.new hostname, ssh_config
    @mysql_connection_settings = {}
  end

  # Install test environment
  #
  def install
    create_clean_test_application
    initialize_environment
  end

  # Copy test application to temporary dirctory
  #
  def create_clean_test_application
    # Clean old test app path
    FileUtils.rm_rf test_app_path
    # Create test app path parent directory, if not exists
    FileUtils.mkdir_p tmp_path
    # Copy test app to new location
    FileUtils.cp_r template_path, test_app_path
  end

  # Initialize rvm and bundler environment
  #
  def initialize_environment
    # Call command at test bundler environment. Not with gem bundler environment
    Bundler.with_clean_env do
      cd test_app_path do
        # Install necessary gems
        `bundle check || bundle install`
        raise "Error running 'bundle install'" unless $?.success?
      end
    end
  end
end

Instance Method Details

#create_clean_test_applicationObject

Copy test application to temporary dirctory



37
38
39
40
41
42
43
44
# File 'lib/dkdeploy/test_environment/application.rb', line 37

def create_clean_test_application
  # Clean old test app path
  FileUtils.rm_rf test_app_path
  # Create test app path parent directory, if not exists
  FileUtils.mkdir_p tmp_path
  # Copy test app to new location
  FileUtils.cp_r template_path, test_app_path
end

#initialize_environmentObject

Initialize rvm and bundler environment



48
49
50
51
52
53
54
55
56
57
# File 'lib/dkdeploy/test_environment/application.rb', line 48

def initialize_environment
  # Call command at test bundler environment. Not with gem bundler environment
  Bundler.with_clean_env do
    cd test_app_path do
      # Install necessary gems
      `bundle check || bundle install`
      raise "Error running 'bundle install'" unless $?.success?
    end
  end
end

#installObject

Install test environment



30
31
32
33
# File 'lib/dkdeploy/test_environment/application.rb', line 30

def install
  create_clean_test_application
  initialize_environment
end