Module: Appril::CLI::Assertions

Included in:
Docker
Defined in:
lib/appril-cli/assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_config_file_exists(dir) ⇒ Object



37
38
39
40
# File 'lib/appril-cli/assertions.rb', line 37

def assert_config_file_exists dir
  return if File.file?(dir / Docker::CONFIG_FILE)
  fatal_error! "#{dir / Docker::CONFIG_FILE} file is missing"
end

#assert_directory_does_not_exists(dir) ⇒ Object



32
33
34
35
# File 'lib/appril-cli/assertions.rb', line 32

def assert_directory_does_not_exists dir
  return unless File.exists?(dir)
  fatal_error! "#{dir} already exists"
end

#assert_directory_exists(dir) ⇒ Object



27
28
29
30
# File 'lib/appril-cli/assertions.rb', line 27

def assert_directory_exists dir
  return if File.directory?(dir)
  fatal_error! "#{dir} should be a directory"
end

#assert_empty_directory(dir) ⇒ Object



22
23
24
25
# File 'lib/appril-cli/assertions.rb', line 22

def assert_empty_directory dir
  return if Dir[dir / '*'].empty?
  fatal_error! "#{dir} should be empty"
end

#assert_installable_path(path) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/appril-cli/assertions.rb', line 5

def assert_installable_path path
  if path == WORKING_DIR
    assert_empty_directory(path)
  else
    assert_directory_does_not_exists(path)
  end
end

#assert_is_app_dir(dir) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/appril-cli/assertions.rb', line 13

def assert_is_app_dir dir
  return if %w[
    core
    base/components
    config
  ].all? {|e| File.exists?(dir / e)}
  fatal_error! "#{dir} does not look like a Appril app dir"
end