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.17.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.16.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.15.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.14.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.13.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.12.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.11.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.10.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.9.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.8.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.7.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.6.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.5.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.4.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.3.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.2.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.1.pre lib/active_model/validations/file_readability_validator.rb
ecm_rbac-2.0.0 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-1.2.1 lib/active_model/validations/file_readability_validator.rb
ecm_rbac-1.2.0 lib/active_model/validations/file_readability_validator.rb