Class: ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/config_manager.rb

Instance Method Summary collapse

Instance Method Details

#get_file_linesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/config_manager.rb', line 30

def get_file_lines
    unless self.is_docker_compose_folder
        puts "docker-compose.yml does not exists in current directory. Choose one of the available environments."
        puts
        wp_docker_list
        exit
    end

    file_lines = File.readlines("docker-compose.yml")
    unless file_lines.grep(/## wp-docker ##/).any?
        puts "Invalid docker-compose.yml"
        exit
    end

    file_lines
end

#get_wp_container_nameObject



2
3
4
5
6
7
8
# File 'lib/config_manager.rb', line 2

def get_wp_container_name
    file_lines = get_file_lines

    container_line = file_lines.grep(/container_name: wpd_web/)
    name = container_line[0].scan(/wpd_.+_\d+/)[0]
    return name    
end

#get_wp_container_portObject



18
19
20
21
22
23
24
# File 'lib/config_manager.rb', line 18

def get_wp_container_port
    file_lines = get_file_lines

    container_line = file_lines.grep(/:80"/)
    ret = container_line[0].scan(/(\d+):(\d+)"/)
    return ret[0][0]
end

#get_wp_environment_nameObject



10
11
12
13
14
15
16
# File 'lib/config_manager.rb', line 10

def get_wp_environment_name
    file_lines = get_file_lines

    container_line = file_lines.grep(/container_name: wpd_web/)
    name = container_line[0].scan(/(wpd_[a-z]+)_(.+\d+)/)
    return name[0][1]
end

#is_docker_compose_directoryObject



26
27
28
# File 'lib/config_manager.rb', line 26

def is_docker_compose_directory

end

#is_docker_compose_folderObject



47
48
49
# File 'lib/config_manager.rb', line 47

def is_docker_compose_folder
    File.file?("docker-compose.yml")
end