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
ecm_rbac-1.0.1 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-1.0.0 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-0.0.10 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-0.0.9 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-0.0.8 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-0.0.4 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-0.0.3 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-0.0.2 lib/active_model/validations/file_readability_validator.rb