Module: AbideDevUtils::Validate
- Defined in:
- lib/abide_dev_utils/validate.rb
Class Method Summary collapse
- .directory(path) ⇒ Object
- .file(path, extension: nil) ⇒ Object
- .filesystem_path(path) ⇒ Object
- .hashable(obj) ⇒ Object
- .not_empty(thing, msg) ⇒ Object
Class Method Details
.directory(path) ⇒ Object
20 21 22 23 |
# File 'lib/abide_dev_utils/validate.rb', line 20 def self.directory(path) filesystem_path(path) raise AbideDevUtils::Errors::PathNotDirectoryError, path unless File.directory?(path) end |
.file(path, extension: nil) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/abide_dev_utils/validate.rb', line 11 def self.file(path, extension: nil) filesystem_path(path) raise AbideDevUtils::Errors::PathNotFileError, path unless File.file?(path) return if extension.nil? file_ext = extension.match?(/^\.[A-Za-z0-9]+$/) ? extension : ".#{extension}" raise AbideDevUtils::Errors::FileExtensionIncorrectError, extension unless File.extname(path) == file_ext end |
.filesystem_path(path) ⇒ Object
7 8 9 |
# File 'lib/abide_dev_utils/validate.rb', line 7 def self.filesystem_path(path) raise AbideDevUtils::Errors::FileNotFoundError, path unless File.exist?(path) end |
.hashable(obj) ⇒ Object
29 30 31 32 33 |
# File 'lib/abide_dev_utils/validate.rb', line 29 def self.hashable(obj) return if obj.respond_to?(:to_hash) || obj.respond_to?(:to_h) raise AbideDevUtils::Errors::NotHashableError, obj end |
.not_empty(thing, msg) ⇒ Object
25 26 27 |
# File 'lib/abide_dev_utils/validate.rb', line 25 def self.not_empty(thing, msg) raise AbideDevUtils::Errors::ObjectEmptyError, msg if thing.empty? end |