Class: OptParseValidator::OptFilePath
- Defined in:
- lib/opt_parse_validator/opts/file_path.rb
Overview
Implementation of the FilePath Option
Instance Attribute Summary
Attributes inherited from OptBase
Instance Method Summary collapse
- #allowed_attrs ⇒ Object
- #check_extensions(path) ⇒ Object
-
#initialize(option, attrs = {}) ⇒ OptFilePath
constructor
:extensions [ Array | String ] The allowed extension(s).
Methods inherited from OptPath
#check_directory, #check_executable, #check_file, #check_readable, #check_writable, #validate
Methods inherited from OptBase
#choices, #default, #normalize, #required?, #required_unless, #to_long, #to_s, #to_sym, #validate, #value_if_empty
Constructor Details
#initialize(option, attrs = {}) ⇒ OptFilePath
:extensions [ Array | String ] The allowed extension(s)
7 8 9 10 11 |
# File 'lib/opt_parse_validator/opts/file_path.rb', line 7 def initialize(option, attrs = {}) super(option, attrs) @attrs.merge!(file: true) end |
Instance Method Details
#allowed_attrs ⇒ Object
13 14 15 16 |
# File 'lib/opt_parse_validator/opts/file_path.rb', line 13 def allowed_attrs # :extensions is put at the first place [:extensions] + super end |
#check_extensions(path) ⇒ Object
18 19 20 21 22 |
# File 'lib/opt_parse_validator/opts/file_path.rb', line 18 def check_extensions(path) return if [*attrs[:extensions]].include?(path.extname.delete('.')) fail "The extension of '#{path}' is not allowed" end |