Module: FailFast::CheckFileSystem

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

Instance Method Summary collapse

Instance Method Details

#directory_exists(path, options = {}) ⇒ Object

Ensure the value is an existing directory

Usage

directory_exists '/tmp'
directory_exists '/tmp', :message => 'custom message'


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

def directory_exists(path, options={})
  unless File.exists?(path) && File.directory?(path)
    add_error ErrorDetails.new(nil, :directory_not_found, path, options[:message])
  end
end

#directory_exists_for(raw_key, *params) ⇒ Object

Ensure the key value is an existing directory

Usage

directory_exists_for 'foo/config'
directory_exists_for 'foo/config', :message => 'custom message'


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

def directory_exists_for(raw_key, *params)
  p = key_value_regexp_options(raw_key, params)
  key, options = p.key, p.options

  return unless has_value_for raw_key, :message => options[:message]

  path = value_for_deep_key(key)
  unless File.exists?(path) && File.directory?(path)
    add_error ErrorDetails.new(key, :directory_not_found, p.value, options[:message])
  end
end

#file_exists(path, options = {}) ⇒ Object

Ensure the value is an existing file

Usage

file_exists '~/.bash_profile'
file_exists '~/.bash_profile', :message => 'custom message'


22
23
24
25
26
# File 'lib/fail_fast/extensions/check_file_system.rb', line 22

def file_exists(path, options={})
  unless File.exists?(path) && File.file?(path)
    add_error ErrorDetails.new(nil, :file_not_found, path, options[:message])
  end
end

#file_exists_for(raw_key, *params) ⇒ Object

Ensure the key value is an existing file exists

Usage

file_exists_for 'foo/config/app.yml'
file_exists_for 'foo/config/app.yml', :message => 'custom message'


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

def file_exists_for(raw_key, *params)
  p = key_value_regexp_options(raw_key, params)
  key, options = p.key, p.options

  return unless has_value_for raw_key, :message => options[:message]

  path = value_for_deep_key(key)
  unless File.exists?(path) && File.file?(path)
    add_error ErrorDetails.new(key, :file_not_found, p.value, options[:message])
  end
end