Class: Waw::Validation::FileValidator

Inherits:
Validator show all
Defined in:
lib/waw/validation/file_validator.rb

Instance Method Summary collapse

Methods inherited from Validator

#&, #===, #=~, #convert_and_validate, #not, #|

Methods included from Helpers

#all_missing?, #any_missing?, #argument_safe, #error, #is_missing?, #missings_to_nil, #no_missing?, #to_validator

Constructor Details

#initialize(opts = {}) ⇒ FileValidator

Returns a new instance of FileValidator.



5
6
7
# File 'lib/waw/validation/file_validator.rb', line 5

def initialize(opts = {})
  @options = opts
end

Instance Method Details

#seems_a_file?(f) ⇒ Boolean

Seems a valid file

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/waw/validation/file_validator.rb', line 10

def seems_a_file?(f)
  return false unless File.file?(f)
  return true unless @options
  @options.each_pair do |key, value|
    case key
      when :extension
        return false unless value==File.extname(f)
      else
        raise Waw::Error, "Unexpected FileValidator option #{key} : #{value}"
    end
  end
  true
end

#validate(*values) ⇒ Object



24
25
26
# File 'lib/waw/validation/file_validator.rb', line 24

def validate(*values)
  values.all?{|f| seems_a_file?(f)}
end