Module: FailFast::FileExists
- Defined in:
- lib/fail_fast/extensions/file_exists.rb
Instance Method Summary collapse
-
#file_exists(path, options = {}) ⇒ Object
Ensure the value is an existing file.
-
#file_exists_for(raw_key, *params) ⇒ Object
Ensure the key value is an existing file exists.
Instance Method Details
#file_exists(path, options = {}) ⇒ Object
Ensure the value is an existing file
Usage
file_exists '~/.bash_profile'
file_exists '~/.bash_profile', :message => 'custom message'
10 11 12 13 14 15 16 |
# File 'lib/fail_fast/extensions/file_exists.rb', line 10 def file_exists(path, ={}) success = File.exists?(path) && File.file?(path) unless success add_error ErrorDetails.new(nil, :file_not_found, path, [:message]) end success 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'
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fail_fast/extensions/file_exists.rb', line 24 def file_exists_for(raw_key, *params) p = (raw_key, params) key, = p.key, p. return false unless has_value_for raw_key, :message => [:message] path = value_for_deep_key(key) success = File.exists?(path) && File.file?(path) unless success add_error ErrorDetails.new(key, :file_not_found, p.value, [:message]) end success end |