Class: MachineConfigure::Validator

Inherits:
Object
  • Object
show all
Includes:
Helpers::Message
Defined in:
lib/machine_configure/validator.rb

Overview

This class should validate that dependencies are installed (docker-machine).

Constant Summary collapse

BASE_APPS =

Default command-line apps, which need to be available.

[
  'docker-machine'
]

Constants included from Helpers::Message

Helpers::Message::MESSAGE_PADDING, Helpers::Message::STACK_TRACE_PADDING, Helpers::Message::STACK_TRACE_SIZE

Instance Method Summary collapse

Methods included from Helpers::Message

error_no_stack_trace!, error_yes_stack_trace!

Constructor Details

#initializeValidator

Returns a new instance of Validator.



11
12
13
# File 'lib/machine_configure/validator.rb', line 11

def initialize
  @validated_apps = []
end

Instance Method Details

#validate_apps(*apps) ⇒ Object

Check if given apps (or default BASE_APPS), are available from the command-line. Throw an error and exit if any aren’t available.



23
24
25
26
27
# File 'lib/machine_configure/validator.rb', line 23

def validate_apps *apps
  apps.flatten.each do |appname|
    validate_app appname
  end
end

#validate_base_appsObject

Calls #validate_apps for BASE_APPS.



16
17
18
# File 'lib/machine_configure/validator.rb', line 16

def validate_base_apps
  validate_apps *BASE_APPS
end

#validate_directories(*directories) ⇒ Object

Check that the given directories exist, and are directories.



47
48
49
50
51
# File 'lib/machine_configure/validator.rb', line 47

def validate_directories *directories
  directories.flatten.each do |directory|
    validate_directory directory
  end
end

#validate_directories_dont_exist(*directories) ⇒ Object

Check that the given directories do NOT exist.



54
55
56
57
58
# File 'lib/machine_configure/validator.rb', line 54

def validate_directories_dont_exist *directories
  directories.flatten.each do |directory|
    validate_directory_doesnt_exist directory
  end
end

#validate_machine_name(name) ⇒ Object

Check that the given name exists for docker-machine.



31
32
33
34
35
36
# File 'lib/machine_configure/validator.rb', line 31

def validate_machine_name name
  validate_app 'docker-machine'
  error(
    "Docker machine `#{name}' is not available."
  )  unless (docker_machine_exists? name)
end

#validate_no_machine_name(name) ⇒ Object

Check that the given name does not exist for docker-machine.



40
41
42
43
# File 'lib/machine_configure/validator.rb', line 40

def validate_no_machine_name name
  validate_app 'docker-machine'
  prompt_to_replace_docker_machine name  if (docker_machine_exists? name)
end

#validate_zip_file_export(zip_file) ⇒ Object

Check that the given zip_file doesn’t exist already but that the path leading to the file does exist.



63
64
65
66
67
68
69
# File 'lib/machine_configure/validator.rb', line 63

def validate_zip_file_export zip_file
  path = File.dirname zip_file
  error(
    "The path to the zip file `#{path.to_path}' doesn't exist."
  )  unless (is_directory? path)
  prompt_to_replace_file zip_file  if (is_file? zip_file)
end

#validate_zip_file_import(zip_file) ⇒ Object

Similar to #validate_zip_file_export, but don’t prompt for overwriting, etc. The zip file has to exist in this case.



74
75
76
77
78
# File 'lib/machine_configure/validator.rb', line 74

def validate_zip_file_import zip_file
  error(
    "The zip file `#{zip_file.to_s}' doesn't exist or is a directory."
  )  unless (is_file? zip_file)
end