Module: FailFast::CheckFileSystem

Defined in:
lib/fail_fast/extensions/check_file_system.rb

Instance Method Summary collapse

Instance Method Details

#directory_exists(path, *params) ⇒ Object

Ensure the value is an existing directory

Usage

directory_exists '/tmp'


9
10
11
12
13
# File 'lib/fail_fast/extensions/check_file_system.rb', line 9

def directory_exists(path, *params)
  unless File.exists?(path) && File.directory?(path)
    add_error ErrorDetails.new(nil, :directory_not_found, path)
  end
end

#directory_exists_for(key, *params) ⇒ Object

Ensure the key value is an existing directory

Usage

directory_exists_for 'foo/config'


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fail_fast/extensions/check_file_system.rb', line 31

def directory_exists_for(key, *params)
  return unless has_value_for key

  p = key_value_regexp_options(key, params)
  key, options = p.key, p.options

  path = value_for_deep_key(key)

  unless File.exists?(path) && File.directory?(path)
    add_error ErrorDetails.new(key, :directory_not_found, p.value)
  end
end

#file_exists(path, *params) ⇒ Object

Ensure the value is an existing file

Usage

file_exists '~/.bash_profile'


20
21
22
23
24
# File 'lib/fail_fast/extensions/check_file_system.rb', line 20

def file_exists(path, *params)
  unless File.exists?(path) && File.file?(path)
    add_error ErrorDetails.new(nil, :file_not_found, path)
  end
end

#file_exists_for(key, *params) ⇒ Object

Ensure the key value is an existing file exists

Usage

file_exists_for 'foo/config/app.yml'


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fail_fast/extensions/check_file_system.rb', line 49

def file_exists_for(key, *params)
  return unless has_value_for key

  p = key_value_regexp_options(key, params)
  key, options = p.key, p.options

  path = value_for_deep_key(key)

  unless File.exists?(path) && File.file?(path)
    add_error ErrorDetails.new(key, :file_not_found, p.value)
  end
end