Sha256: cc7305b9588e00febb56188ba4e990fb5187314f113bf3fa0061dc27df7ae1a6

Contents?: true

Size: 898 Bytes

Versions: 68

Compression:

Stored size: 898 Bytes

Contents

module ActiveModel
  module Validations
    class FileReadabilityValidator < ::ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        filename = File.expand_path(value) if !value.nil? && value.respond_to?(:to_s)
        if filename.nil?
          record.errors.add(attribute, options[:message] || :filename_is_nil)
          return
        end
        unless File.exists?(filename)
          record.errors.add(attribute, options[:message] || :file_not_existent, filename: filename)
          return
        end
        unless File.file?(filename)
          record.errors.add(attribute, options[:message] || :file_not_file, filename: filename)
          return
        end
        unless File.readable?(filename)
          record.errors.add(attribute, options[:message] || :file_not_readable, filename: filename)
          return
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
cmor_rbac-0.0.38.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.37.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.36.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.35.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.34.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.33.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.32.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.31.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.30.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.29.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.28.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.27.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.26.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.25.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.24.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.22.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.21.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.20.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.19.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.18.pre lib/active_model/validations/file_readability_validator.rb